Commit 176fb356 authored by simonpj@microsoft.com's avatar simonpj@microsoft.com
Browse files

Complete -fmono-pat-binds patch

When adding the experimental -fmono-pat-binds, I forgot to check
for type signatures of the now-monomorphic patterns.  This patch
completes the job.

I documented the design too:
   http://haskell.galois.com/cgi-bin/haskell-prime/trac.cgi/wiki/MonomorphicPatternBindings
parent 015675fc
...@@ -643,9 +643,21 @@ tcLhs sig_fn (FunBind { fun_id = L nm_loc name, fun_infix = inf, fun_matches = m ...@@ -643,9 +643,21 @@ tcLhs sig_fn (FunBind { fun_id = L nm_loc name, fun_infix = inf, fun_matches = m
tcLhs sig_fn bind@(PatBind { pat_lhs = pat, pat_rhs = grhss }) tcLhs sig_fn bind@(PatBind { pat_lhs = pat, pat_rhs = grhss })
= do { mb_sigs <- mapM (tcInstSig_maybe sig_fn) names = do { mb_sigs <- mapM (tcInstSig_maybe sig_fn) names
; mono_pat_binds <- doptM Opt_MonoPatBinds
-- With -fmono-pat-binds, we do no generalisation of pattern bindings
-- But the signature can still be polymoprhic!
-- data T = MkT (forall a. a->a)
-- x :: forall a. a->a
-- MkT x = <rhs>
-- The function get_sig_ty decides whether the pattern-bound variables
-- should have exactly the type in the type signature (-fmono-pat-binds),
-- or the instantiated version (-fmono-pat-binds)
; let nm_sig_prs = names `zip` mb_sigs ; let nm_sig_prs = names `zip` mb_sigs
tau_sig_env = mkNameEnv [ (name, sig_tau sig) | (name, Just sig) <- nm_sig_prs] get_sig_ty | mono_pat_binds = idType . sig_id
| otherwise = sig_tau
tau_sig_env = mkNameEnv [ (name, get_sig_ty sig)
| (name, Just sig) <- nm_sig_prs]
sig_tau_fn = lookupNameEnv tau_sig_env sig_tau_fn = lookupNameEnv tau_sig_env
tc_pat exp_ty = tcPat (LetPat sig_tau_fn) pat exp_ty unitTy $ \ _ -> tc_pat exp_ty = tcPat (LetPat sig_tau_fn) pat exp_ty unitTy $ \ _ ->
......
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