[Haskell-cafe] an idea for modifiyng data/newtype syntax: use `::=` instead of `=`
tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Sat Aug 8 21:38:26 UTC 2015
On Sat, Aug 08, 2015 at 11:32:59PM +0200, MigMit wrote:
> >>>> Well, it's certainly unsupported by evidence. Because third-party code CAN
> >>>> distinguish between those.
> >>> OK, show me the code!
> >> I did. You removed it when quoting.
> > Reinstating:
> >>> Prelude> newtype A = A Int deriving Show
> >>> Prelude> data B = B !Int deriving Show
> >>> Prelude> let x = case x of A n -> A 1 in x
> >>> A 1
> >>> Prelude> let y = case y of B n -> B 1 in y
> >>> *** Exception: <<loop>>
> > This isn't third party code. It knows about the constructors of A and B.
> 1) This might be the code written by someone using your library/framework.
> In which case it would know about A and B.
Then it's up to me to define and document whatever strictness properties I
want for my constructors.
To reiterate: I'm *not* suggesting replacing
newtype A = A a
data A = A!
in existing code. Of course that won't work. But for *new* datatypes
choosing one rather than the other gives no difference in terms of
> 2) It might be generated by the Template Haskell — which is free to use
> whatever constructor is fed into it.
OK, so show me what goes wrong!
More information about the Haskell-Cafe