[Haskell-cafe] an idea for modifiyng data/newtype syntax: use `::=` instead of `=`

MigMit miguelimo38 at yandex.ru
Sat Aug 8 21:32:59 UTC 2015


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

2) It might be generated by the Template Haskell — which is free to use whatever constructor is fed into it.



More information about the Haskell-Cafe mailing list