-
Notifications
You must be signed in to change notification settings - Fork 4
/
ExtI.hs
31 lines (21 loc) · 863 Bytes
/
ExtI.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
-- * Lack of extensibility in the data type view
module ExtI where
import qualified Intro1 as Old
-- Attempt to add a new expression form: multiplication
-- We would like to reuse the old code, in Intro1.hs (show the code)
-- We don't want to extend the data type declaration in Intro1.hs
-- as that would require adjusting and recompiling all the code
-- that uses Intro1.hs (in particular, all the interpreters)
data Exp = EOld Old.Exp
| Mul Exp Exp -- add a new variant
-- An extended sample expression
tim2 = Mul (EOld (Old.Lit 7)) (EOld Old.ti1)
-- tim2 is a bit ugly. But this is only a part of a problem
-- Why does the following fails to type check?
{-
tim1 = EOld (Old.Add (Old.Lit 7)
(Old.Neg (Mul (EOld (Old.Lit 1)) (EOld (Old.Lit 2)))))
-}
-- So, we are stuck. Data type variants are NOT extensible.
main = do
print "Done"