mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-21 17:12:50 -06:00
added smart constructors for types in PGF
This commit is contained in:
@@ -27,8 +27,9 @@ module PGF(
|
|||||||
languages, abstractName, languageCode,
|
languages, abstractName, languageCode,
|
||||||
|
|
||||||
-- * Types
|
-- * Types
|
||||||
Type,
|
Type, Hypo,
|
||||||
showType, readType,
|
showType, readType,
|
||||||
|
mkType, mkHypo, mkDepHypo, mkImplHypo,
|
||||||
categories, startCat,
|
categories, startCat,
|
||||||
|
|
||||||
-- * Functions
|
-- * Functions
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
module PGF.Type ( Type(..), Hypo,
|
module PGF.Type ( Type(..), Hypo,
|
||||||
readType, showType,
|
readType, showType,
|
||||||
|
mkType, mkHypo, mkDepHypo, mkImplHypo,
|
||||||
pType, ppType, ppHypo ) where
|
pType, ppType, ppHypo ) where
|
||||||
|
|
||||||
import PGF.CId
|
import PGF.CId
|
||||||
@@ -10,7 +11,7 @@ import qualified Text.PrettyPrint as PP
|
|||||||
import qualified Text.ParserCombinators.ReadP as RP
|
import qualified Text.ParserCombinators.ReadP as RP
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
|
|
||||||
-- | To read a type from a 'String', use 'read' or 'readType'.
|
-- | To read a type from a 'String', use 'readType'.
|
||||||
data Type =
|
data Type =
|
||||||
DTyp [Hypo] CId [Expr]
|
DTyp [Hypo] CId [Expr]
|
||||||
deriving (Eq,Ord,Show)
|
deriving (Eq,Ord,Show)
|
||||||
@@ -31,6 +32,25 @@ readType s = case [x | (x,cs) <- RP.readP_to_S pType s, all isSpace cs] of
|
|||||||
showType :: [CId] -> Type -> String
|
showType :: [CId] -> Type -> String
|
||||||
showType vars = PP.render . ppType 0 vars
|
showType vars = PP.render . ppType 0 vars
|
||||||
|
|
||||||
|
-- | creates a type from list of hypothesises, category and
|
||||||
|
-- list of arguments for the category. The operation
|
||||||
|
-- @mkType [h_1,...,h_n] C [e_1,...,e_m]@ will create
|
||||||
|
-- @h_1 -> ... -> h_n -> C e_1 ... e_m@
|
||||||
|
mkType :: [Hypo] -> CId -> [Expr] -> Type
|
||||||
|
mkType hyps cat args = DTyp hyps cat args
|
||||||
|
|
||||||
|
-- | creates hypothesis for non-dependent type i.e. A
|
||||||
|
mkHypo :: Type -> Hypo
|
||||||
|
mkHypo ty = (Explicit,wildCId,ty)
|
||||||
|
|
||||||
|
-- | creates hypothesis for dependent type i.e. (x : A)
|
||||||
|
mkDepHypo :: CId -> Type -> Hypo
|
||||||
|
mkDepHypo x ty = (Explicit,x,ty)
|
||||||
|
|
||||||
|
-- | creates hypothesis for dependent type with implicit argument i.e. ({x} : A)
|
||||||
|
mkImplHypo :: CId -> Type -> Hypo
|
||||||
|
mkImplHypo x ty = (Implicit,x,ty)
|
||||||
|
|
||||||
pType :: RP.ReadP Type
|
pType :: RP.ReadP Type
|
||||||
pType = do
|
pType = do
|
||||||
RP.skipSpaces
|
RP.skipSpaces
|
||||||
|
|||||||
Reference in New Issue
Block a user