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 (Dimitri DeFigueiredo)
   2. Re:  phantom types and record syntax (Karl Voelker)
   3. Re:  phantom types and record syntax (Imants Cekusins)


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

Message: 1
Date: Wed, 17 Jun 2015 20:21:20 -0600
From: Dimitri DeFigueiredo <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] phantom types and record syntax
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed

Thanks for the thoughts.

This is funny, so the constructor has the same name but is for different 
types. I think this is specially bad for security. I'm going to be 
paranoid about it now.

Dimitri


On 17/06/15 00:42, Karl Voelker wrote:
> 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
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



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

Message: 2
Date: Wed, 17 Jun 2015 21:42:32 -0700
From: Karl Voelker <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] phantom types and record syntax
Message-ID:
        <1434602552.3301193.298646825.2d24f...@webmail.messagingengine.com>
Content-Type: text/plain

On Wed, Jun 17, 2015, at 07:21 PM, Dimitri DeFigueiredo wrote:
> This is funny, so the constructor has the same name but is for different 
> types. I think this is specially bad for security. I'm going to be 
> paranoid about it now.

If you would like to give some more background on your use case, we may
be able to suggest better ways to ensure safety through types.

-Karl


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

Message: 3
Date: Thu, 18 Jun 2015 10:04:12 +0200
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] phantom types and record syntax
Message-ID:
        <cap1qinzecnx-rd1hq14iqktzc8mkumojqc-e-gsbugzyusp...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

function signature makes a difference. in this example, try swapping
the signature of function convertToReq

it seems implicit conversion happens depending on signature (and usual
constraints), yes


module Phantom where

data ReqTime = ReqTime
data AckTime = AckTime


-- convertToReq :: Order AckTime -> Order ReqTime  -- builds
convertToReq :: Order AckTime -> Order AckTime  -- error
convertToReq o = o{price = 1}



data Order a = Order { price  ::Double, volume ::Int, timestamp ::Int }

main :: Order ReqTime
main =   expectReq conv
      where ack = initAckTime
            conv = convertToReq ack

initAckTime:: Order AckTime
initAckTime = Order {
   timestamp = 0,
   price = 2.1,
   volume = 3
   }



expectReq::Order ReqTime -> Order ReqTime
expectReq o = o


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

Subject: Digest Footer

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


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

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

Reply via email to