[Haskell-cafe] Are records type safe?
Bulat Ziganshin
bulat.ziganshin at gmail.com
Thu May 4 10:23:03 EDT 2006
Hello Tom,
Thursday, May 4, 2006, 5:20:54 PM, you wrote:
> I was experimenting with records this morning and discovered a slight oddity...
> data Rec = RecA { a :: Int } | RecB { a :: Int, b :: Bool } deriving Show
> main :: IO ()
> main = do
> print (b (RecB { a = 1, b = True })) -- Works
> print (b (RecA { a = 1 })) -- Doesn't
> Of course extracting "b" from a record constructed with "RecA" is
> illegal, but the compiler did not warn against it (ghc -W). I was
> expecting a warning similar to non-exhaustive pattern matching.
> Are records with optional fields really type safe?
it shpuld be a runtime check. seems that Haskell is so changed your
mind that you expect that compiler should check anything at compile time
:)
--
Best regards,
Bulat mailto:Bulat.Ziganshin at gmail.com
More information about the Haskell-Cafe
mailing list