Popularity
7.8
Growing
Activity
2.9
-
19
5
14

Monthly Downloads: 253
Programming language: Haskell
License: BSD 3-clause "New" or "Revised" License
Tags: Data    
Latest version: v0.3.0

data-fix alternatives and similar packages

Based on the "Data" category.
Alternatively, view data-fix alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of data-fix or a related project?

Add another 'Data' Package

README

data-fix - fixpoint types and recursion schemes

Build Status

Fixpoint types and recursion schemes. If you define your AST as fixpoint type, you get fold and unfold operations for free.

Fix f = f (Fix f)

Type f should be a Functor if you want to use simple recursion schemes or 'Traversable' if you want to use monadic recursion schemes. This style allows you to express recursive functions in non-recursive manner. You can imagine that a non-recursive function holds values of the previous iteration.

Little example:

type List a = Fix (L a)

data L a b = Nil | Cons a b

instance Functor (L a) where
  fmap f x = case x of
    Nil      -> Nil
    Cons a b -> Cons a (f b)

length :: List a -> Int
length = cata $ \x -> case x of
  Nil      -> 0
  Cons _ n -> n + 1

sum :: Num a => List a -> a
sum = cata $ \x -> case x of
  Nil      -> 0
  Cons a s -> a + s

Acknowledgements

Thanks for contribution to: Matej Kollar, Herbert Valerio Riedel