[Haskell-cafe] Record syntax, reopening a can of worms.
John Meacham
john at repetae.net
Sun May 27 02:14:44 CEST 2012
Is it any more ridiculous than
> f x at Nothing {} = fromJust x
> main = print (f Nothing)
crashing at run time? That is what you are expressing with your first
one. This issue is completely unrelated to the named field syntax,
they behave exactly like data types with non-named fields.
However, you can achieve something like what you want with phantom types.
> data ALike
> data BLike
>data MyData t = A {a::Int,
> b::Int} |
> B {c::Int}
> mkA x y = A x y :: MyData ALike
> mkB x = B x :: MyData BLike
then you can write functions of
'MyData ALike' to indicate it will only have 'A' as a constructor
'MyData BLike' to indicate it will only have 'B'
and 'forall t . MyData t' for functions that can take a general MyData
that can have either.
John
More information about the Haskell-Cafe
mailing list