Do we really want to treat every newtype wrappers as a form of 'id'?
For example:

    newtype Nat = Nat Integer   -- must always be positive

A possible rule (doesn't actually typecheck, but you get the idea):

    forall (x :: Nat). sqrt (x * x) = x

If we ignore newtyping we get an incorrect rewrite rule.  It depends
on the exact implementation of which 'id's would be recognised.


On 20 October 2010 21:08, James Andrew Cook <[email protected]> wrote:
> On Oct 20, 2010, at 11:58 AM, Gregory Crosswhite <[email protected]> 
> wrote:
>
>> On 10/20/10 4:09 AM, Simon Peyton-Jones wrote:
>>> No, this isn't optimised.  The trouble is that you write (map Foo xs), but 
>>> GHC doesn't know about 'map'.  We could add a special case for map, but 
>>> then you'd soon want (mapTree Foo my_tree).
>>
>> How about a special case for fmap?  That seems like it should handle a lot 
>> of cases.
>>
>
> Or even better, a special handling of 'id' in rules pragmas that would cause 
> any rule matching id to also match any newtype constructor or projection. Or 
> have the compiler automatically add rules that map all newtype wrappers and 
> unwrappers to unsafeCoerce and make sure that unsafeCoerce has rules for map, 
> fmap, (.), etc.
>
> --James_______________________________________________
> Haskell-Cafe mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



-- 
Push the envelope. Watch it bend.
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to