From 6113840d21ba9faa58742af67f32e463ca4f64a9 Mon Sep 17 00:00:00 2001 From: Philipp Hausmann Date: Thu, 18 Dec 2014 18:05:18 +0100 Subject: [PATCH] Remove case-default from Core API, document case behaviour (see issue #39 ) --- EHC/changelog.md | 2 +- EHC/src/ehc/Core/API.chs | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/EHC/changelog.md b/EHC/changelog.md index a1a3b6a77..2a9707482 100644 --- a/EHC/changelog.md +++ b/EHC/changelog.md @@ -2,7 +2,7 @@ ## 1.1.8.2 -- +- [core, api] Removed broken default alternative from case expressions API ## 1.1.8.1 - 20141217 diff --git a/EHC/src/ehc/Core/API.chs b/EHC/src/ehc/Core/API.chs index fb8686a1d..1915a4ab6 100644 --- a/EHC/src/ehc/Core/API.chs +++ b/EHC/src/ehc/Core/API.chs @@ -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 @@ -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 @@ -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 @@ -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