Embedding higher kinded types (monads!) into the untyped lambda calculus

前端 未结 3 900
谎友^
谎友^ 2021-02-04 17:58

It\'s possible to encode various types in the untyped lambda calculus through higher order functions.

Examples:
zero  = λfx.      x
one   = λfx.     fx
two   = λ         


        
3条回答
  •  有刺的猬
    2021-02-04 18:15

    Well, we already have tuples and booleans, hence we can represent Either and in turn any non-recursive sum type based on that:

    type Either a b = (Bool, (a, b))
    type Maybe a    = Either () a
    

    And Maybe is a member of the Monad type class. Translation to lambda notation is left as exercise.

提交回复
热议问题