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

Sebastiaan Visser sfvisser at cs.uu.nl
Tue Jun 30 04:34:11 EDT 2009

On Jun 30, 2009, at 2:44 AM, Conal Elliott wrote:
> I just uploaded a new package [1] for generalized booleans, which  
> provides type classes with generalizations of boolean values &  
> operations, if-then-else, Eq and Ord.  These values & types come up  
> for me with every new deep DSEL, and I think they do for others as  
> well.  The design space has some tricky trade-offs, and I'm not  
> positive I've found the optimum yet.  Users & comments are very  
> welcome.  Please direct discussion to the haskell-cafe list (rather  
> than haskell list).


Good work!

Together with Tom Lokhorst I've been working on something very  
similar. We've been using a rather consistent way of eliminating data  
structures that scales well to other data types. Although we are also  
using functional dependencies I think we might want to change them to  
type families.

> class Bool f r | f -> r where
>   bool  :: r -> r -> f -> r
>   false :: f
>   true  :: f
> class Maybe f a r | f -> a, f -> r where
>   maybe   :: r -> (a -> r) -> f a -> r
>   nothing :: f a
>   just    :: a -> f a
> class Either f a b r | f -> a, f -> b, f -> r where
>   either :: (a -> r) -> (b -> r) -> f a b -> r
>   left   :: a -> f a b
>   right  :: b -> f a b
Currently we have a very limited and somewhat messy code base on  
github[1] which shows how to instantiate these types to get back the  
original Haskell functionality and how to produce JavaScript code that  
runs in a browser. The the JavaScript instance is very much the same  
as I used in my FRP to JS EDSL[4]. Next target will, off course, be  
Objective C. :-)
Our code is not yet release worthy and probably never will be in this  
form. But is would be very nice to see some kind of generalized  
prelude evolving.

> [1]: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ 
> Boolean
>    - Conal

Sebastiaan Visser

[1] http://github.com/tomlokhorst/AwesomePrelude/tree/master
[2] http://github.com/sebastiaanvisser/frp-js

More information about the Haskell-Cafe mailing list