Let me guess there is a data PL as a sum type of records:
data PL = Functional { name :: String, pure :: Bool }
| ObjectOriented { name :: String, multipleInheritance :: Bool }The type of pure is:
λ> :type pure
pure :: PL -> Bool
You may have already noticed the problem.
λ> let haskell = Functional "Haskell" True
λ> pure haskell
True
λ> let cpp = ObjectOriented "CPP" True
λ> pure cpp
*** Exception: No match in record selector pure
The problem is that it's a runtime error. Because pure has the type PL -> Bool, there is no way to enforce pure to be applied only to Functionals in compile time.
A possible solution will be like below.
data Fuctional = Functional { name :: String, pure :: Bool }
data ObjectOriented = ObjectOriented { name :: String, multipleInheritance :: Bool }
data PL = Functional' Functional
| ObjectOriented' ObjectOrientedThen the type of pure will be Fuctional -> Bool.
Thanks!