haskell - Catamorphism in F# -


i'm reading wikipedia article catamorphisms , moment able reproduce haskell examples in f# except part :

type algebra f = f -> -- generic f-algebras  newtype fix f = iso { inviso :: f (fix f) } -- gives initial algebra functor f  cata :: functor f => algebra f -> (fix f -> a) -- catamorphism fix f cata alg = alg . fmap (cata alg) . inviso -- note inviso , alg map in opposite directions 

is possible in f#?

if you're thinking of expressing generic folds on arbitrary container types, a'la recursion schemes, directly within f# (or clr matter) type system - you're out of luck. of required machinery missing in language - crucially higher kinded types.

hkt's can encoded in f# using technique called defunctionalization. there f# library based on concepts paper - higher. in fact, implements fix, cata/ana/hylomorphisms , algebras proofs of concept. don't have gauge of how works though, both in terms of performance , ease of use.

other that, can implement folds specialized containers hand, obviating need hkt's. there's classic series of blog posts on implementing catamorphisms here. it's worth reading - beside folds goes in-depth programming in continuation-passing style.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -