Thursday, May 20, 2010

Why floating point is shit

take 50 $ zipWith id (map (\z->(^(2^z))) [1..]) (iterate (sqrt) 2)
view raw gistfile1.hsc hosted with ❤ by GitHub

Tuesday, May 11, 2010

Implicit Folds in Haskell (for those jealous of LISP)

Ever wish you could do things like (+ 3 4 5) from LISP, but in Haskell? Wish no more with the beautiful FoldyList datatype! An example instance for Show is given but feel free to write your own, otherwise the code is next to useless.

module FoldyList where
data FoldyList a =
FoldyCons (FoldyHead a) (FoldyTail a)
type FoldyHead a = (a -> a -> a)
type FoldyTail a = [a]
instance Show q => Show (FoldyList q) where
show (FoldyCons x y) = show $ foldr1 x y
flist :: FoldyList Int
flist = FoldyCons (+) [3,4,5]
main = print flist
view raw FoldyList.hs hosted with ❤ by GitHub