
Recent Posts
Recent Comments
Archives
Categories
Meta
Advertisements
Demonstrate how to carry to implicit states with Monads : import System.Random import Control.Monad.State type RandomState = State StdGen getRandom ::(Random a) => RandomState a getRandom = get >>= \g > let (a,g’) = random g in put g’ >> … Continue reading
import Control.Monad combo :: [[a]]>[[a]]>[[a]] combo = liftM2 (++) combiner :: [[a]]>[[a]] combiner xs = (foldr (.) id $ take (n1) $ cycle [combo xs] ) xs where n = length xs this does permutations samples — combiner [“a”,”b”] [“aa”,”ab”,”ba”,”bb”] … Continue reading
Haskell ZipWithN in termas of zipWithN1: zip’ :: [a]>[b]>[(a,b)] zip’ xs ys = zipWith (\x y > (x,y) ) xs ys zipWith3′ :: (a>b>c>d)>[a]>[b]>[c]>[d] zipWith3′ f xs = zipWith id . zipWith f xs zipWith4′ :: (a>b>c>d>e)>[a]>[b]>[c]>[d]>[e] zipWith4′ f xs … Continue reading
liftM’ :: Monad m => (a>r)>m a > m r liftM’ f m = m >>= \a> return (f a) liftM2′ :: Monad m => (a>b>r)>m a > m b > m r liftM2′ f m1 m2 = liftM’ f … Continue reading
one of useful lifters for Monads are : LiftM ..family liftM2 :: Monad m => (a1 > a2 > r) > m a1 > m a2 > m r But not very good for chaining in ,a better derivative for … Continue reading
import Data.Array lazy folding foldlA f zero a = go f zero (indices a) where go f zero (x:xs) = go f (f zero (a ! x)) xs go _ zero [] = zero inplace evaluation using seq foldlA’ f … Continue reading