[Haskell-cafe] ANN: package Boolean: Generalized booleans

Sebastiaan Visser sfvisser at cs.uu.nl
Tue Jun 30 11:53:23 EDT 2009

On Jun 30, 2009, at 5:24 PM, Conal Elliott wrote:
> Hi Sebastiaan,
> I like your extensions of generalized booleans to other common  
> Haskell types!
> I also prefer using type families to fundeps.  In this case I didn't  
> because of some awkwardness with vector operations, but I'm going to  
> try again.
> I'm confused about your particular fundep choice.  For instance,
> class Bool f r | f -> r where
>  bool  :: r -> r -> f -> r
>  false :: f
>  true  :: f
> Do you *really* mean that the boolean type f determines the value  
> type r?

Yes, that is really what I mean. This can be used to enforce that the  
return value of elimination can be restricted by the boolean type.  
This is especially useful when using GADTs to encode your domain  

For example, take this simple JavaScript language:
   data Js a where
     Prim :: String -> Js a                -- Primitive embedding.
     App :: Js (a -> b) -> Js a -> Js b    -- Function application.

   data JsBool

Now the functional dependencies can be used to enforce that  
eliminating booleans in the Js domain always returns a value in the Js  
   instance Bool (Js JsBool) (Js r) where
     bool f t c = Prim "(function ifthenelse (f, t, c) c ? t : f)"  
`App` f `App` t `App` c
     true  = Prim "true"
     false = Prim "false"
Getting rid of this fundep and using type families will probably be a  
lot more intuitive.

Any suggestions on how to enforce elimination to be able to go from  
`Js JsBool -> Js r' using other techniques?
> Regards,   - Conal
> ...

Sebastiaan Visser

More information about the Haskell-Cafe mailing list