Brian Lewis | 22 Jun 11:26 2013

data constructor names

Say you write
data Callback = Error ... | ...
because one of the kinds of callbacks you need to model is an error
callback.

Then, later, you write
data Error = ...
to model some error that can happen.

They're both good names, but there's a conflict. So I started thinking I
should prefix my constructor names like
data Callback = CallbackError ... | ...
It will work, but it's not the nicest looking.

I discovered I can write
data Callback = Callback'Error ... | ...
Where can I find the syntax reference to see what's allowed? Will people
kill me if I start doing this?

I could import qualified, but in my case, there would be too many
modules.

Thanks for any advice.
Suzuki Tomohiro | 22 Jun 12:25 2013
Picon

Re: data constructor names

I found syntax reference here.



consym -> (: {symbol | :})<reservedop>

symbol -> ascSymbol | uniSymbol<special | _ | : | " | '>

constrs -> constr1 | ... | constrn (n>=1)




Regards,
Tomo

On Saturday, June 22, 2013, Brian Lewis wrote:
Say you write
data Callback = Error ... | ...
because one of the kinds of callbacks you need to model is an error
callback.

Then, later, you write
data Error = ...
to model some error that can happen.

They're both good names, but there's a conflict. So I started thinking I
should prefix my constructor names like
data Callback = CallbackError ... | ...
It will work, but it's not the nicest looking.

I discovered I can write
data Callback = Callback'Error ... | ...
Where can I find the syntax reference to see what's allowed? Will people
kill me if I start doing this?

I could import qualified, but in my case, there would be too many
modules.

Thanks for any advice.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Tom Ellis | 22 Jun 13:15 2013
Picon

Re: data constructor names

On Sat, Jun 22, 2013 at 04:26:14AM -0500, Brian Lewis wrote:
> Say you write
> data Callback = Error ... | ...
[...]
> 
> Then, later, you write
> data Error = ...
[...]
> 
> They're both good names, but there's a conflict.

What do you mean by a conflict?  That's fine as far as the compiler is
concerned because constructors live in a different namespace from types.

If you meant it will be too confusing for the programmer that's fair enough.

Tom
Tobias Dammers | 22 Jun 22:00 2013
Picon

Re: data constructor names

On Sat, Jun 22, 2013 at 12:15:07PM +0100, Tom Ellis wrote:
> On Sat, Jun 22, 2013 at 04:26:14AM -0500, Brian Lewis wrote:
> > Say you write
> > data Callback = Error ... | ...
> [...]
> > 
> > Then, later, you write
> > data Error = ...
> [...]
> > 
> > They're both good names, but there's a conflict.
> 
> What do you mean by a conflict?  That's fine as far as the compiler is
> concerned because constructors live in a different namespace from types.
> 

I think he meant something like:

    data Callback = Error Error | Success

	data Error = Error String

...in which case there is a clash for the identifier "Error" at the
value level.

Gmane