[Haskell-cafe] ANN: package Boolean: Generalized booleans
tom at lokhorst.eu
Tue Jun 30 15:05:35 EDT 2009
It compiles fine :-)
If you want, you can take a look at this  version of the code (or
the tarball ).
Load Main.hs in GHCi and run `test`, it will evaluate to `True`.
Then, in the source code, switch the type of `test` from `P.Bool` to
`Js JsBool` (in the comments) and run `test` again, now it will
The code is still very immature (basically only that one example
works), but it demonstrates our intend.
On Tue, Jun 30, 2009 at 8:21 PM, Conal Elliott<conal at conal.net> wrote:
> Does this code compile? I'd expect that
> instance Bool (Js JsBool) (Js r) where
> violates the fundep, since it applies for *all* values of r, not just to
> - Conal
> On Tue, Jun 30, 2009 at 8:53 AM, Sebastiaan Visser <sfvisser at cs.uu.nl>
>> On Jun 30, 2009, at 5:24 PM, Conal Elliott wrote:
>>> Hi Sebastiaan,
>>> I like your extensions of generalized booleans to other common Haskell
>>> 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
>>> 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 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 domain:
>> 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
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe