Type synonym for lambda-based / church booleans

Suppose true ( t) and false ( f) are defined as follows:

> let t = \x -> \_ -> x
t :: t1 -> t -> t1
> let f = \_ -> \y -> y
f :: t1 -> t -> t

Is there a way to define a synonym for a type that can capture the type of both booleans?

+4
source share
1 answer

Given that Church Booleans basically either choose the first or second option, and you want to use them in something like

if' :: Boolean -> a -> a -> a
if' b tval fval = b tval fval

such that

if' t 1 0 == 1
if' f 1 0 == 0

you need to limit the type of one type variable a:

{-# LANGUAGE RankNTypes #-}

type Boolean = forall a. a -> a -> a

Here's an article that details Haskell's Booleans elements .

+5
source

Source: https://habr.com/ru/post/1668597/


All Articles