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

Tom Lokhorst 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 [1] version of the code (or
the tarball [2]).

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
evaluate to a JavaScript expression.

The code is still very immature (basically only that one example
works), but it demonstrates our intend.

- Tom

[1]: http://github.com/tomlokhorst/AwesomePrelude/tree/master
[2]: http://github.com/tomlokhorst/AwesomePrelude/tarball/master

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
> one.
>
>    - Conal
>
> On Tue, Jun 30, 2009 at 8:53 AM, Sebastiaan Visser <sfvisser at cs.uu.nl>
> wrote:
>>
>> 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 language.
>>
>> 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 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
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>


More information about the Haskell-Cafe mailing list