Re: [Haskell-cafe] Type system trickery

2009-06-23 Thread Andrew Coppin
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

Re: [Haskell-cafe] Type system trickery

2009-06-23 Thread Brandon S. Allbery KF8NH
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.

Re: [Haskell-cafe] Type system trickery

2009-06-23 Thread Ross Mellgren
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

Re: [Haskell-cafe] Type system trickery

2009-06-23 Thread David Menendez
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

Re: [Haskell-cafe] Type system trickery

2009-06-22 Thread Brent Yorgey
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

Re: [Haskell-cafe] Type system trickery

2009-06-22 Thread Andrew Coppin
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

Re: [Haskell-cafe] Type system trickery

2009-06-22 Thread Niklas Broberg
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*

Re: [Haskell-cafe] Type system trickery

2009-06-22 Thread Thomas DuBuisson
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

Re: [Haskell-cafe] Type system trickery

2009-06-22 Thread Andrew Coppin
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

Re: [Haskell-cafe] Type system trickery

2009-06-22 Thread Ross Mellgren
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

[Haskell-cafe] Type system trickery

2009-06-21 Thread 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 | Bar Foobar | Zoo Foobar I want the type system to

Re: [Haskell-cafe] Type system trickery

2009-06-21 Thread Daniel Fischer
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

Re: [Haskell-cafe] Type system trickery

2009-06-21 Thread Andrew Coppin
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

Re: [Haskell-cafe] Type system trickery

2009-06-21 Thread Niklas Broberg
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

Re: [Haskell-cafe] Type system trickery

2009-06-21 Thread Andrew Coppin
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. :-/

Re: [Haskell-cafe] Type system trickery

2009-06-21 Thread Niklas Broberg
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

Re: [Haskell-cafe] Type system trickery

2009-06-21 Thread David Menendez
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

Re: [Haskell-cafe] Type system trickery

2009-06-21 Thread Andrew Coppin
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