Skip to content

mattneary/Thunctor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Thunctor

Safe recursion with monads.

@unroll
def fact(me, n):
    return (Thunk(1)
        if not n
        else me(n-1).map(lambda x: x * n))
$ pip install thunctor

The Thunk Monad

The thunk monad allows for a lazy value to be constructed whose manipulations will be delayed. These values can then be unrolled without exhausting the callstack.

  • Thunk : a → Thunk a
  • Thunk#bind : Thunk a → (a → Thunk b) → Thunk b
  • Thunk#map : Thunk a → (a → b) → Thunk b

A thunk returning function can be transformed to a normal function using unroll.

  • unroll : ((*x, **y) → Thunk a) → (*x, **y) → a

About

Safe recursion with monads

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages