← This doesn't mean that everything is all right!
Implement functionality from Haskell's Prelude in C++11. Just for fun. Errors guaranteed.
After playing around with functional immutable lists in C++11, I though it would be nice to have the functionality from Haskell's Prelude (or at least the interesting functions) in C++. This is an attempt to implement some of the functionality on STL containers. Whenever possible, functionality from the STL is used.
-
map :: (a -> b) -> [a] -> [b]
-
(++) :: [a] -> [a] -> [a]
asjoin
-
filter :: (a -> Bool) -> [a] -> [a]
-
head :: [a] -> a
-
last :: [a] -> a
-
tail :: [a] -> [a]
-
init :: [a] -> [a]
-
null :: [a] -> Bool
-
length :: [a] -> Int
-
(!!) :: [a] -> Int -> a
asat
-
reverse :: [a] -> [a]
-
foldl :: (b -> a -> b) -> b -> [a] -> b
-
foldl1 :: (a -> a -> a) -> [a] -> a
-
foldr :: (a -> b -> b) -> b -> [a] -> b
-
foldr1 :: (a -> a -> a) -> [a] -> a
-
and :: [Bool] -> Bool
-
or :: [Bool] -> Bool
-
any :: (a -> Bool) -> [a] -> Bool
-
all :: (a -> Bool) -> [a] -> Bool
-
sum :: Num a => [a] -> a
-
product :: Num a => [a] -> a
-
concat :: [[a]] -> [a]
-
concatMap :: (a -> [b]) -> [a] -> [b]
-
maximum :: Ord a => [a] -> a
-
minimum :: Ord a => [a] -> a
-
scanl :: (b -> a -> b) -> b -> [a] -> [b]
-
scanl1 :: (a -> a -> a) -> [a] -> [a]
-
scanr :: (a -> b -> b) -> b -> [a] -> [b]
-
scanr1 :: (a -> a -> a) -> [a] -> [a]
Without lazy evaluation, there is not really any way to produce infinite lists. Maybe I'll implement these functions with an additional size parameter.
-
take :: Int -> [a] -> [a]
-
drop :: Int -> [a] -> [a]
-
splitAt :: Int -> [a] -> ([a], [a])
-
takeWhile :: (a -> Bool) -> [a] -> [a]
-
dropWhile :: (a -> Bool) -> [a] -> [a]
-
span :: (a -> Bool) -> [a] -> ([a], [a])
-
break :: (a -> Bool) -> [a] -> ([a], [a])
-
elem :: Eq a => a -> [a] -> Bool
-
notElem :: Eq a => a -> [a] -> Bool
-
lookup :: Eq a => a -> [(a, b)] -> Maybe b
-
zip :: [a] -> [b] -> [(a, b)]
-
zip3 :: [a] -> [b] -> [c] -> [(a, b, c)]
-
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
-
zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
-
unzip :: [(a, b)] -> ([a], [b])
-
unzip3 :: [(a, b, c)] -> ([a], [b], [c])