Records in Haskell

Ian Lynagh igloo at earth.li
Fri Mar 2 02:18:56 CET 2012


On Fri, Mar 02, 2012 at 01:04:13AM +0000, AntC wrote:
> 
> Let me explain better what I mean by "two private namespaces", then we'll try 
> to understand how your proposal goes ...
> 
>   module T             where
>       data FieldT = Field
>       data RecT = RecT{ Field :: Int }
>       ...
>   module U             where
>       data FieldU = Field
>       data RecU = RecU{ Field :: Bool }
>       ...
>   module V             where
>       import T                             -- also consider either/both
>       import U                             -- imports hiding (Field)
>       data RecV = RecV{ Field :: String }  -- am I sharing this Field?
>                                            -- who with?

Ah, I see. No, you couldn't do that, just as you couldn't do
    v = Field
You would need to say
    data RecV = RecV{ T.Field :: String }

>       ... r.Field ...           -- is this valid?, if not what is?

r!T.Field (I took the liberty of using a random different symbol for
field access, for clarity).

>       ... r{ Field = e }        -- likewise

r{ T.Field = e }

> (Oh yeah, imports and hiding: how do I do that for these non-String-type-Kinds?
> And is this allowed?:
>       data NotaField = Constr Int Bool
>       data AmIaRec = AmI{ Constr :: String }

No.


Thanks
Ian




More information about the Glasgow-haskell-users mailing list