Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  phantom types and record syntax (Karl Voelker)


----------------------------------------------------------------------

Message: 1
Date: Tue, 16 Jun 2015 23:42:06 -0700
From: Karl Voelker <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] phantom types and record syntax
Message-ID:
        <1434523326.2978810.297687737.0022a...@webmail.messagingengine.com>
Content-Type: text/plain

On Tue, Jun 16, 2015, at 05:43 PM, Dimitri DeFigueiredo wrote:
> I am a little suprised that this program compiles in GHC:
> 
> ----
> data ReqTime = ReqTime
> data AckTime = AckTime
> 
> data Order a = Order { price  ::Double, volume ::Int, timestamp ::Int }
> 
> convertToReq :: Order AckTime -> Order ReqTime
> convertToReq o = o{price = 1}
> 
> main = putStrLn "Hi!"
> ----

I found it surprising, too. But, if you look in the Haskell report
(https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-540003.15.3),
record update is defined by a "desugaring" translation. So your
convertToReq desugars (roughly) to:

convertToReq o = case o of
    Order v1 v2 v3 -> Order 1 v2 v3

Unfortunately, the report does not have any commentary on why it is the
way it is.

-Karl


------------------------------

Subject: Digest Footer

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


------------------------------

End of Beginners Digest, Vol 84, Issue 28
*****************************************

Reply via email to