Skip to content

Commit

Permalink
Remove case-default from Core API, document case behaviour (see issue U…
Browse files Browse the repository at this point in the history
  • Loading branch information
phile314 committed Dec 18, 2014
1 parent 911692e commit 6113840
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion EHC/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 1.1.8.2

-
- [core, api] Removed broken default alternative from case expressions API

## 1.1.8.1 - 20141217

Expand Down
22 changes: 15 additions & 7 deletions EHC/src/ehc/Core/API.chs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
-- - Calling Haskell functions which use the haskell class system is not (yet?) supported.
-- - Avoiding name clashes is the responsibility of the user. The behaviour if duplicate
-- names exists is undefined.
--
--
-- TODO:
--
-- - Should we add PatRest_Var? Does it actually work? (The HS frontend doesn't seem to use it?)
-- - Float, Double literals
--
module %%@{%{EH}%%}Core.API
(
-- * Core AST
Expand Down Expand Up @@ -83,7 +90,7 @@ module %%@{%{EH}%%}Core.API
-- ** Case
-- | Scrutinizes an expression and executes the appropriate alternative.
-- The scrutinee of a case statement is required to be in WHNF (weak head normal form).
, mkCaseDflt
, mkCase

, mkAlt
, mkPatCon
Expand Down Expand Up @@ -284,13 +291,13 @@ ctagNil = AC.ctagNil
-- **************************************

-- TODO verify that this sorting is always correct (see also AbstractCore/Utils.chs)
-- | A Case expression, possibly with a default value.
mkCaseDflt :: EC.CExpr -- ^ The scrutinee. Required to be in WHNF.
-- | A Case expression. The alternatives must be exhaustive, they must cover
-- all possible constructors.
mkCase :: EC.CExpr -- ^ The scrutinee. Required to be in WHNF.
-> [EC.CAlt] -- ^ The alternatives.
-> Maybe EC.CExpr -- ^ The default value. (TODO what is the behaviour if it is Nothing?)
-> EC.CExpr
mkCaseDflt e as def =
AC.acoreCaseDflt e (sortBy (comparing (getTag . fst . AC.acoreUnAlt)) as) def
mkCase e as =
AC.acoreCaseDflt e (sortBy (comparing (getTag . fst . AC.acoreUnAlt)) as) Nothing
where -- gets the tag for constructors, or returns 0 if this is not a constructor pattern
-- TODO is this always safe?
getTag t = case AC.acorePatMbCon t of
Expand All @@ -310,7 +317,8 @@ mkPatCon :: CTag -- ^ The constructor to match.
-> EC.CPat
mkPatCon = AC.acorePatCon

-- | patrest, empty TODO what does it mean?
-- | The whole case scrutinee has already been matched on. There is nothing left.
-- (If there is still something left, runtime behaviour is undefined)
mkPatRestEmpty :: EC.CPatRest
mkPatRestEmpty = AC.acorePatRestEmpty

Expand Down

0 comments on commit 6113840

Please sign in to comment.