haskpy.types.uncurried.uncurried

uncurried(f)[source]

Decorator for transforming functions into monads

This can be useful for converting value constructors into function monads, so that one can use map and other methods of a function monad. For instance, List is a value constructor but doesn’t have monadic methods. By wrapping it with uncurried, you can treat it like a normal uncurried function:

>>> from haskpy import List, Maybe, Just
>>> MaybeList = uncurried(List).map(lambda xs: xs.sequence(Maybe))
>>> MaybeList(Just(10), Just(20), Just(30))
Just(List(10, 20, 30))

The above example converted List constructor into a special constructor that converts List (Maybe a) into Maybe (List a) automatically. This can be useful so that you can easily create lists inside your own custom monads.