Giter Club home page Giter Club logo

data-fix's Introduction

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

data-fix's People

Contributors

anton-k avatar cstrahan avatar flip111 avatar hvr avatar phadej avatar ploeh avatar xkollar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.