Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Replicate function for lists.

  • Loading branch information...
commit 1e7682b99d090553c191e8a7661faf6e68517f21 1 parent 47ac375
Sebastiaan Visser authored

Showing 1 changed file with 4 additions and 1 deletion. Show diff stats Hide diff stats

  1. +4 1 src/Generic/Data/List.hs
5 src/Generic/Data/List.hs
@@ -15,11 +15,14 @@ instance (FunC j, ListC j) => Functor j [] where
15 15 fmap f = foldr (\a r -> f a `cons` r) nil
16 16
17 17 singleton :: ListC j => j a -> j [a]
18   -singleton a = cons a nil
  18 +singleton a = a `cons` nil
19 19
20 20 foldr :: (FunC j, ListC j) => (j a -> j b -> j b) -> j b -> j [a] -> j b
21 21 foldr f b xs = fix (\r -> lam (list b (\y ys -> f y (r `app` ys)))) `app` xs
22 22
  23 +replicate :: (ListC j, NumC j, Eq j Num, BoolC j, FunC j) => j Num -> j a -> j [a]
  24 +replicate n a = fix (\r -> lam (\y -> bool nil (a `cons` (r `app` (y - 1))) (y == 0))) `app` n
  25 +
23 26 (++) :: (FunC j, ListC j) => j [a] -> j [a] -> j [a]
24 27 xs ++ ys = foldr cons ys xs
25 28

0 comments on commit 1e7682b

Please sign in to comment.
Something went wrong with that request. Please try again.