[Haskell-cafe] Need an example of new type constructor with zero data constructors
amindfv at gmail.com
amindfv at gmail.com
Fri Aug 12 16:28:09 UTC 2016
Another use:
class Foo a e | a -> e where
foo :: a -> Either e a
instance Foo Int Void where
foo :: Int -> Either Void Int
foo x = Right (x + 1)
Even though it's an "Either", we're saying we will never (ignoring bottom) return a "Left" value.
Tom
> El 12 ago 2016, a las 11:28, Michael Burge <michaelburge at pobox.com> escribió:
>
> One use is when you want an open sum type rather than a closed one. For example, you might want users of your library to add their own 'constructors'. Then, they serve a purpose similar to a constructor that takes no arguments:
>
> {-# LANGUAGE EmptyDataDecls #-}
>
> class Color a where
> rgb :: a -> (Int, Int, Int)
>
> data Red
> data Green
> data Blue
>
> instance Color Red where
> rgb _ = (255, 0, 0)
>
> instance Color Green where
> rgb _ = (0, 255, 0)
>
> instance Color Blue where
> rgb _ = (0, 0, 255)
>
> data ColorADT = Color_Red | Color_Green | Color_Blue
> rgb_adt Color_Red = (255, 0, 0)
> rgb_adt Color_Green = (0, 255, 0)
> rgb_adt Color_Blue = (0, 0, 255)
>
>
>> On Fri, Aug 12, 2016 at 8:16 AM, James Brown <james.brown5374 at gmail.com> wrote:
>> What's the purpose to allow data declarations with no constructors?
>>
>>> On Fri, Aug 12, 2016 at 11:08 AM, Sergey N. Yashin <yashin.sergey at gmail.com> wrote:
>>> For zero data constructors you need to use only EmptyDataDecls extension.
>>>
>>> _______________________________________________
>>> Haskell-Cafe mailing list
>>> To (un)subscribe, modify options or view archives go to:
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>>> Only members subscribed via the mailman list are allowed to post.
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>> Only members subscribed via the mailman list are allowed to post.
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160812/456d9d96/attachment-0001.html>
More information about the Haskell-Cafe
mailing list