Is it possible to use a <> constructor in analogy to [] ?

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

Is it possible to use a <> constructor in analogy to [] ?

Martin Drautzburg
Hello all,

I've written my own Read and Show instances for a type, which is essentially

data Crust a = Open [a] | Closed [a]

"Show" does something like

*Main> Closed [1,2,3]
<1,2,3>
*Main> Open [1,2,3]
<1,2,3..>

And Read faithully parses each stings and turns it into a Crust again.

Problem is: when I just type <1,2,3..> in GHCi I get a "parse error on input ‘<’". However when I spell out the
custructor as above it parses it okay.

Is it possible at all to write my own <> constructor, or something like it=
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to use a <> constructor in analogy to [] ?

Carl Eyeinsky

If you write the literal in a string, apply 'read' and specify the type, then it should work.

If you write it in a string literal, then it might be that you need to use defaulting to get it to evaluate to Crust.

If you write just a bare <...> in ghci then afaik that won't ever work, as there's a fixed set of literals ghc's parser accepts.

On Jan 27, 2016 9:44 PM, "martin" <[hidden email]> wrote:
Hello all,

I've written my own Read and Show instances for a type, which is essentially

data Crust a = Open [a] | Closed [a]

"Show" does something like

*Main> Closed [1,2,3]
<1,2,3>
*Main> Open [1,2,3]
<1,2,3..>

And Read faithully parses each stings and turns it into a Crust again.

Problem is: when I just type <1,2,3..> in GHCi I get a "parse error on input ‘<’". However when I spell out the
custructor as above it parses it okay.

Is it possible at all to write my own <> constructor, or something like it=
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners