Perhaps this is a trivial question and I'm just not thinking about it correctly. If so, my apologies.
I would like to implement the lambda calculus true and false functions in Haskell and then use those to implement if-then-else. Here's what I did.
true :: t1 -> t2 -> t1
true x y = x
false :: t1 -> t2 -> t2
false x y = y
-- ifThenElse :: (t2 -> t1 -> t) -> t2 -> t1 -> t
ifThenElse cond thenPart elsePart = cond thenPart elsePart
The commented-out ifThenElse type is what GHC generates. My concern is that t in that type should be constrained to be either t1 or t2. Can I write a type for ifThenElse that accomplishes this?
condshould be eithertrueorfalse. For Haskellcondis a generic function. - Willem Van OnsemifThenElse :: (t -> t -> t) -> t -> t -> t. - melpomenecondmust be eithertrueorfalse. I'm asking how to require that it be that.. - RussAbbottRankNTypesand demandifThenElsetake a condition of typeforall t. t -> t -> t. - pigworker