data constructor names

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

data constructor names

Brian Lewis-3
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
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: data constructor names

Suzuki Tomohiro
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
<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;Haskell-Cafe@haskell.org&#39;)">Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: data constructor names

Tom Ellis
In reply to this post by Brian Lewis-3
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

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: data constructor names

Tobias Dammers
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.

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe