Module

Transit.Class.CurryN

Package
purescript-transit
Repository
m-bock/purescript-transit

A type class for converting functions that take nested tuple arguments into curried functions.

Example:

f :: Int /\ String /\ Unit -> String
f (x /\ s /\ _) = s <> show x

curried :: Int -> String -> String
curried = curryN f

#CurryN Source

class CurryN args result curried | args result -> curried, args curried -> result where

Converts a function from nested tuple arguments to a curried function.

  • args: The nested tuple type of arguments (must end with Unit)
  • result: The return type of the function
  • curried: The curried function type

Members

  • curryN :: (args -> result) -> curried

Instances

  • CurryN Unit result result

    Base case: when the tuple is Unit, the function has no arguments and we simply apply it to unit.

  • (CurryN args result curried) => CurryN (Tuple arg args) result (arg -> curried)

    Recursive case: for arg /\ args, we curry the first argument arg and recursively curry the remaining arguments args.