[Haskell-cafe] Re: Type Synonyms

2007-10-10 Thread Tom Davies
Andrew Wagner  gmail.com> writes:

> 
> If you change your type declarations to 'newtype' declarations, I
> believe you would get the effect that you want, depending on what you
> mean by 'equivalent'. In that case, Foo and Bar would essentially be
> strings, but you could not use either of them in a place where the
> other is expected, nor where a String is expected. See
> http://haskell.org/haskellwiki/Newtype for more information. Hope this
> helps!

I wanted to avoid wrapping the string with a constructor.

I suppose what I'm really asking for is for each type to implicitly define a 
'type class with no methods', and to be able to create new instances of
 that type class which simply behave as the underlying
type.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Type Synonyms

2007-10-11 Thread Henning Thielemann


On Thu, 11 Oct 2007, Tom Davies wrote:


Andrew Wagner  gmail.com> writes:


If you change your type declarations to 'newtype' declarations, I
believe you would get the effect that you want, depending on what you
mean by 'equivalent'. In that case, Foo and Bar would essentially be
strings, but you could not use either of them in a place where the
other is expected, nor where a String is expected. See
http://haskell.org/haskellwiki/Newtype for more information. Hope this
helps!


I wanted to avoid wrapping the string with a constructor.

I suppose what I'm really asking for is for each type to implicitly define a
'type class with no methods', and to be able to create new instances of
that type class which simply behave as the underlying
type.


For custom types you can add phantom type parameters. This way you can 
make types distinct while being able to apply the same functions to their 
values.


Say

data SpecialString usage = SpecialString String


Then you can define a generic function like

  take :: Int -> SpecialString usage -> SpecialString usage

or a specialised function like

  foo :: SpecialString Foo -> SpecialString Foo
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe