Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Replicate function for lists.

  • Loading branch information...
commit 1e7682b99d090553c191e8a7661faf6e68517f21 1 parent 47ac375
Sebastiaan Visser authored
Showing with 4 additions and 1 deletion.
  1. +4 −1 src/Generic/Data/List.hs
5 src/Generic/Data/List.hs
View
@@ -15,11 +15,14 @@ instance (FunC j, ListC j) => Functor j [] where
fmap f = foldr (\a r -> f a `cons` r) nil
singleton :: ListC j => j a -> j [a]
-singleton a = cons a nil
+singleton a = a `cons` nil
foldr :: (FunC j, ListC j) => (j a -> j b -> j b) -> j b -> j [a] -> j b
foldr f b xs = fix (\r -> lam (list b (\y ys -> f y (r `app` ys)))) `app` xs
+replicate :: (ListC j, NumC j, Eq j Num, BoolC j, FunC j) => j Num -> j a -> j [a]
+replicate n a = fix (\r -> lam (\y -> bool nil (a `cons` (r `app` (y - 1))) (y == 0))) `app` n
+
(++) :: (FunC j, ListC j) => j [a] -> j [a] -> j [a]
xs ++ ys = foldr cons ys xs
Please sign in to comment.
Something went wrong with that request. Please try again.