Commit 14880aae authored by Finn Teegen's avatar Finn Teegen

Add syntax extension for existentially quantified types

parent 59d75a24
...@@ -11,6 +11,8 @@ Under development (0.4.1) ...@@ -11,6 +11,8 @@ Under development (0.4.1)
* Split checking and expansion of export specification into two * Split checking and expansion of export specification into two
subsequent steps (by Yannik Potdevin, fixes #1335) subsequent steps (by Yannik Potdevin, fixes #1335)
* Consider parenthesized type expressions in the Curry AST (by Katharina Rahf) * Consider parenthesized type expressions in the Curry AST (by Katharina Rahf)
* Added syntax extension `ExistentialQuantification` that allows the use
of existentially quantified types in data and newtype constructors
Version 0.4.0 Version 0.4.0
============= =============
......
...@@ -28,7 +28,7 @@ module Checks.SyntaxCheck (syntaxCheck) where ...@@ -28,7 +28,7 @@ module Checks.SyntaxCheck (syntaxCheck) where
#if __GLASGOW_HASKELL__ < 710 #if __GLASGOW_HASKELL__ < 710
import Control.Applicative ((<$>), (<*>)) import Control.Applicative ((<$>), (<*>))
#endif #endif
import Control.Monad (unless, when) import Control.Monad ((>=>), unless, when)
import qualified Control.Monad.State as S (State, runState, gets, modify) import qualified Control.Monad.State as S (State, runState, gets, modify)
import Data.List (insertBy, intersect, nub, partition) import Data.List (insertBy, intersect, nub, partition)
import Data.Maybe (isJust, isNothing) import Data.Maybe (isJust, isNothing)
...@@ -495,15 +495,30 @@ checkDecls bindDecl ds = do ...@@ -495,15 +495,30 @@ checkDecls bindDecl ds = do
-- -- --------------------------------------------------------------------------- -- -- ---------------------------------------------------------------------------
checkDeclRhs :: [Ident] -> Decl -> SCM Decl checkDeclRhs :: [Ident] -> Decl -> SCM Decl
checkDeclRhs _ (DataDecl p tc tvs cs) = checkDeclRhs _ (DataDecl p tc tvs cs) =
DataDecl p tc tvs <$> mapM checkDeclLabels cs DataDecl p tc tvs <$> mapM (checkConstrDecl >=> checkDeclLabels) cs
checkDeclRhs bvs (TypeSig p vs ty) = checkDeclRhs _ (NewtypeDecl p tc tvs c) =
NewtypeDecl p tc tvs <$> checkNewconstrDecl c
checkDeclRhs bvs (TypeSig p vs ty) =
(\vs' -> TypeSig p vs' ty) <$> mapM (checkLocalVar bvs) vs (\vs' -> TypeSig p vs' ty) <$> mapM (checkLocalVar bvs) vs
checkDeclRhs _ (FunctionDecl p f eqs) = checkDeclRhs _ (FunctionDecl p f eqs) =
FunctionDecl p f <$> mapM checkEquation eqs FunctionDecl p f <$> mapM checkEquation eqs
checkDeclRhs _ (PatternDecl p t rhs) = checkDeclRhs _ (PatternDecl p t rhs) =
PatternDecl p t <$> checkRhs rhs PatternDecl p t <$> checkRhs rhs
checkDeclRhs _ d = return d checkDeclRhs _ d = return d
checkConstrDecl :: ConstrDecl -> SCM ConstrDecl
checkConstrDecl c@(ConstrDecl _ evs _ _) = checkExistVars evs >> return c
checkConstrDecl c@(ConOpDecl _ evs _ _ _) = checkExistVars evs >> return c
checkConstrDecl c@(RecordDecl _ evs _ _) = checkExistVars evs >> return c
checkNewconstrDecl :: NewConstrDecl -> SCM NewConstrDecl
checkNewconstrDecl c@(NewConstrDecl _ evs _ _) = checkExistVars evs >> return c
checkNewConstrDecl c@(NewRecordDecl _ evs _ _) = checkExistVars evs >> return c
checkExistVars :: [Ident] -> SCM ()
checkExistVars [] = ok
checkExistVars (ev:_) = checkExistentialQuantificationExtension $ idPosition ev
checkDeclLabels :: ConstrDecl -> SCM ConstrDecl checkDeclLabels :: ConstrDecl -> SCM ConstrDecl
checkDeclLabels rd@(RecordDecl _ _ _ fs) = do checkDeclLabels rd@(RecordDecl _ _ _ fs) = do
...@@ -1034,6 +1049,10 @@ checkFPTerm _ (InfixFuncPattern _ _ _) = ok -- do not check again ...@@ -1034,6 +1049,10 @@ checkFPTerm _ (InfixFuncPattern _ _ _) = ok -- do not check again
-- Miscellaneous functions -- Miscellaneous functions
-- --------------------------------------------------------------------------- -- ---------------------------------------------------------------------------
checkExistentialQuantificationExtension :: Position -> SCM ()
checkExistentialQuantificationExtension p = checkUsedExtension p
"Existentially quantified types" ExistentialQuantification
checkFuncPatsExtension :: Position -> SCM () checkFuncPatsExtension :: Position -> SCM ()
checkFuncPatsExtension p = checkUsedExtension p checkFuncPatsExtension p = checkUsedExtension p
"Functional Patterns" FunctionalPatterns "Functional Patterns" FunctionalPatterns
......
...@@ -233,6 +233,8 @@ extensions = ...@@ -233,6 +233,8 @@ extensions =
, "desugar negated literals as negative literal") , "desugar negated literals as negative literal")
, ( NoImplicitPrelude , "NoImplicitPrelude" , ( NoImplicitPrelude , "NoImplicitPrelude"
, "do not implicitly import the Prelude") , "do not implicitly import the Prelude")
, ( ExistentialQuantification , "ExistentialQuantification"
, "enable existentially quantified types")
] ]
-- ----------------------------------------------------------------------------- -- -----------------------------------------------------------------------------
......
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