[Haskell-beginners] phantom types and record syntax

Imants Cekusins imantc at gmail.com
Thu Jun 18 08:04:12 UTC 2015


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


More information about the Beginners mailing list