Commit 8821096a authored by Jan Rasmus Tikovsky 's avatar Jan Rasmus Tikovsky
Browse files

Fixed desugaring of record patterns

parent 69d91016
...@@ -266,6 +266,7 @@ dsNonLinear :: NonLinearEnv -> Pattern -> DsM (NonLinearEnv, Pattern) ...@@ -266,6 +266,7 @@ dsNonLinear :: NonLinearEnv -> Pattern -> DsM (NonLinearEnv, Pattern)
dsNonLinear env l@(LiteralPattern _) = return (env, l) dsNonLinear env l@(LiteralPattern _) = return (env, l)
dsNonLinear env n@(NegativePattern _ _) = return (env, n) dsNonLinear env n@(NegativePattern _ _) = return (env, n)
dsNonLinear env t@(VariablePattern v) dsNonLinear env t@(VariablePattern v)
| isAnonId v = return (env, t)
| v `Set.member` vis = do | v `Set.member` vis = do
v' <- freshMonoTypeVar "_#nonlinear" t v' <- freshMonoTypeVar "_#nonlinear" t
return ((vis, mkStrictEquality v v' : eqs), VariablePattern v') return ((vis, mkStrictEquality v v' : eqs), VariablePattern v')
......
-- record declarations module HaskellRecords (R (C)) where
data R1 = R1 { f11, f13 :: Int, f12 :: Bool }
data R2 = R2 { f21 :: String, f22 :: R2 } data R a = C { l :: Int, x :: a }
newtype R3 = R3 { f31 :: Char } -- construction
r1 = C { l = 42, x = True }
-- record constructions r2 = C {}
r1 :: R1 -- pattern matching
r1 = R1 { f11 = 42, f12 = True, f13 = 4 } fun C { l = 42 } = True
r2 :: R2 fun2 C {} = False
r2 = R2 { f21 = "hello", f22 = r2 }
r3 = R3 'c' -- update
upd r = r { x = False, l = 0 }
-- record selection \ No newline at end of file
answer :: Int
answer = f11 r1
innerRecord :: R2
innerRecord = f22 r2
c :: Char
c = f31 r3
-- record update
r1' :: R1
r1' = R1 { f12 = False }
r2' :: R2
r2' = R2 { f21 = "bye" }
-- pattern matching on records
isAnswer :: R1 -> Bool
isAnswer (R1 { f11 = 42, f12 = b }) = b
firstLetter :: R2 -> Char
firstLetter (R2 { f21 = (c:cs) }) = c
firstLetter _ = 'f'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment