Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MFP compat: s/fail/error/ in compileStmt #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/LambdaCube/Compiler/Statements.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ compileStmt lhs compilegt ds = \case
alts -> compileStmt lhs compileGuardTrees' [TypeAnn n t] alts
fs@(FunAlt n vs _: _) -> case groupBy ((==) `on` fst) [(length vs, n) | FunAlt n vs _ <- fs] of
[gs@((num, _): _)]
| num == 0 && length gs > 1 -> fail $ "redefined " ++ sName n ++ ":\n" ++ show (vcat $ pShow . sourceInfo . snd <$> gs)
| num == 0 && length gs > 1 -> error $ "redefined " ++ sName n ++ ":\n" ++ show (vcat $ pShow . sourceInfo . snd <$> gs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not this change the semantics?
The error is more lazy than fail AFAIK.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclaimer: I'm far from an expert in Haskell (I have a few hobby projects written in it)…

I think if I understood the MonadFail Proposal correctly, fail for Monads that didn't have a "reasonable" fail implementation and will not become MonadFail in the new proposal, was already implemented by calling error (which is part of why they are removing fail for those Monads).

If someone who actually is familiar with the internals of the MFP could confirm this, that would be good to know for sure.

| n `elem` [n' | TypeFamily n' _ <- ds] -> return []
| otherwise -> do
cf <- compilegt (SIName_ (mconcat [sourceInfo n | FunAlt n _ _ <- fs]) (nameFixity n) $ sName n) vs [gt | FunAlt _ _ gt <- fs]
return [StLet n (listToMaybe [t | TypeAnn n' t <- ds, n' == n]{-TODO: fail if more-}) $ lhs n cf]
fs -> fail $ "different number of arguments of " ++ sName n ++ ":\n" ++ show (vcat $ pShow . sourceInfo . snd . head <$> fs)
fs -> error $ "different number of arguments of " ++ sName n ++ ":\n" ++ show (vcat $ pShow . sourceInfo . snd . head <$> fs)
[Stmt x] -> return [x]
where
noTA x = ((Visible, Wildcard SType), x)
Expand Down