Ross Mellgren wrote:
This works for me:
{-# LANGUAGE EmptyDataDecls, GADTs #-}
module Main where
data NoZoo
data Zoo
newtype X = X Int deriving (Show)
newtype Y = Y Char deriving (Show)
data Foobar a where
Foo :: X - Y - Foobar NoZoo
Bar :: X - Y - Foobar NoZoo
Zoo :: Foobar
On Jun 22, 2009, at 14:43 , Andrew Coppin wrote:
data Foobar a where
Foo :: X - Y - Foobar NoZoo
Bar :: X - Y - Foobar NoZoo
Zoo :: Foobar NoZoo - Foobar Zoo
For some reason, if I do this I get endless type check errors. I
have to change the top two back to Foobar a before it will work.
I'm no expert, but it seems like those constructors should return
Foobar NoZoo, unless you're nesting so there could be a Zoo, in which
case the type variable a should transit, for example:
data Foobar a where
Foo :: X - Y - Foobar NoZoo
Bar :: X - Y - Foobar NoZoo
Baz :: Foobar
On Tue, Jun 23, 2009 at 9:25 PM, Ross Mellgrenrmm-hask...@z.odi.ac wrote:
I'm no expert, but it seems like those constructors should return Foobar
NoZoo, unless you're nesting so there could be a Zoo, in which case the type
variable a should transit, for example:
data Foobar a where
Foo
On Sun, Jun 21, 2009 at 09:16:12PM +0100, Andrew Coppin wrote:
Niklas Broberg wrote:
That's what GADTs are for:
data Flag = HasZoo | NoZoo
data Foobar a where
Foo :: Foobar a - Foobar a
Bar :: Foobar a - Foobar a
Zoo :: Foobar a - Foobar HasZoo
Ouch #1: This appears to
Brent Yorgey wrote:
On Sun, Jun 21, 2009 at 09:16:12PM +0100, Andrew Coppin wrote:
Niklas Broberg wrote:
That's what GADTs are for:
data Flag = HasZoo | NoZoo
data Foobar a where
Foo :: Foobar a - Foobar a
Bar :: Foobar a - Foobar a
Zoo :: Foobar a - Foobar HasZoo
Not nearly as annoying as this:
data Foobar a where
Foo :: X - Y - Foobar NoZoo
Bar :: X - Y - Foobar NoZoo
Zoo :: Foobar NoZoo - Foobar Zoo
For some reason, if I do this I get endless type check errors. I have to
change the top two back to Foobar a before it will work. *sigh*
Andrew Coppin said:
data Foobar a where
Foo :: X - Y - Foobar NoZoo
Bar :: X - Y - Foobar NoZoo
Zoo :: Foobar NoZoo - Foobar Zoo
For some reason, if I do this I get endless type check errors. I have to
change the top two back to Foobar a before it will work. *sigh*
That code snippet
Niklas Broberg wrote:
Not nearly as annoying as this:
data Foobar a where
Foo :: X - Y - Foobar NoZoo
Bar :: X - Y - Foobar NoZoo
Zoo :: Foobar NoZoo - Foobar Zoo
For some reason, if I do this I get endless type check errors. I have to
change the top two back to Foobar a before it will
This works for me:
{-# LANGUAGE EmptyDataDecls, GADTs #-}
module Main where
data NoZoo
data Zoo
newtype X = X Int deriving (Show)
newtype Y = Y Char deriving (Show)
data Foobar a where
Foo :: X - Y - Foobar NoZoo
Bar :: X - Y - Foobar NoZoo
Zoo :: Foobar NoZoo - Foobar Zoo
foobar
I have a datatype with about a dozen constructors. I'd like to find a
way to use the type system to prevent one of the constructors from being
used in certain places. But I can't think of a way to do that.
data Foobar =
Foo Foobar |
Bar Foobar |
Zoo Foobar
I want the type system to
Am Sonntag 21 Juni 2009 21:24:24 schrieb Andrew Coppin:
I have a datatype with about a dozen constructors. I'd like to find a
way to use the type system to prevent one of the constructors from being
used in certain places. But I can't think of a way to do that.
data Foobar =
Foo Foobar
Niklas Broberg wrote:
On Sun, Jun 21, 2009 at 9:24 PM, Andrew
Coppinandrewcop...@btinternet.com wrote:
data Foobar =
Foo Foobar |
Bar Foobar |
Zoo Foobar
I want the type system to track whether or not Zoo has been used in a
specific value. Sure, you can check for it at runtime, but
On Sun, Jun 21, 2009 at 9:24 PM, Andrew
Coppinandrewcop...@btinternet.com wrote:
I have a datatype with about a dozen constructors. I'd like to find a way to
use the type system to prevent one of the constructors from being used in
certain places. But I can't think of a way to do that.
data
Niklas Broberg wrote:
That's what GADTs are for:
data Flag = HasZoo | NoZoo
data Foobar a where
Foo :: Foobar a - Foobar a
Bar :: Foobar a - Foobar a
Zoo :: Foobar a - Foobar HasZoo
Ouch #1: This appears to instantly disable deriving the Eq, Ord and Show
instances I want. :-/
That's what GADTs are for:
data Flag = HasZoo | NoZoo
Eh, I wrote this a bit fast obviously (no dependent types here).
Like Daniel Fischer wrote, these should rather be separate data types, i.e.
data HasZoo
data NoZoo
The rest is still correct though.
data Foobar a where
Foo :: Foobar a
On Sun, Jun 21, 2009 at 4:00 PM, Andrew
Coppinandrewcop...@btinternet.com wrote:
Niklas Broberg wrote:
On Sun, Jun 21, 2009 at 9:24 PM, Andrew
Coppinandrewcop...@btinternet.com wrote:
I want the type system to track whether or not Zoo has been used in a
specific value. Sure, you can check
David Menendez wrote:
If you don't need code that's polymorphic between Foobar HasZoo and
Foobar NoZoo, you could just newtype Foobar and only export smart
constructors.
Unfortunately I want to be able to print both of them out. (After all,
the printing algorithm is identical whether Zoo
18 matches
Mail list logo