SaplStruct.dcl 2.14 KB
Newer Older
1 2 3 4 5 6 7 8 9
definition module Sapl.SaplStruct

import StdString, StdOverloaded
import Sapl.SaplTokenizer
import Data.Maybe

/**
* Possible function types and language constructs.
*/
10
:: FuncType = FTRecord SaplVar [SaplTypedVar]
11
			| FTADT SaplVar [SaplConstructor]
12 13 14
			| FTCAF SaplTypedVar SaplTerm
			| FTMacro SaplTypedVar SaplTerm [SaplTypedVar]
			| FTFunc SaplTypedVar SaplTerm [SaplTypedVar]
15

16
:: SaplConstructor 	= SaplConstructor SaplVar Int [SaplTypedVar]
17 18 19

:: SaplTerm = SLit Literal
			| SVar SaplVar
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
20 21
			| SApplication SaplTerm [SaplTerm]
			| SCase SaplTerm [(SaplPattern, SaplTerm)]
22
			| SLet SaplTerm [SaplLetDef]
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
23 24
			| SSelect SaplTerm SaplType Int
			| SUpdate SaplTerm SaplType [(Int, SaplTerm)]			
25 26
			| SAbortBody			

27
:: SaplLetDef = SaplLetDef SaplTypedVar SaplTerm
28

29 30 31 32 33 34
:: SaplName :== String

:: SaplVar = NormalVar SaplName Int 
		   | StrictVar SaplName Int

:: SaplTypedVar = TypedVar SaplVar SaplType
35 36 37 38 39

:: SaplPattern = PCons String [SaplVar]
			   | PLit Literal
			   | PDefault

40 41
:: SaplType = Type String | NoType

42 43 44 45 46 47 48
instance toString SaplVar

// I don't provide instances of (==) and (<) here because multiple good way can be imagined...
eqVarByName :: !SaplVar !SaplVar -> Bool
ltVarByName :: !SaplVar !SaplVar -> Bool
eqVarByNameLevel :: !SaplVar !SaplVar -> Bool
ltVarByNameLevel :: !SaplVar !SaplVar -> Bool
49

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
removeTypeInfo :: !SaplTypedVar -> SaplVar

class eqStrictVar v :: !String !v -> Bool
class isStrictVar v :: !v -> Bool
class toNormalVar v :: !v -> v
class toStrictVar v :: !v -> v
class unpackVar v :: !v -> String

instance eqStrictVar SaplVar
instance eqStrictVar SaplTypedVar
instance isStrictVar SaplVar
instance isStrictVar SaplTypedVar
instance toNormalVar SaplVar
instance toNormalVar SaplTypedVar
instance toStrictVar SaplVar
instance toStrictVar SaplTypedVar
instance unpackVar SaplVar
instance unpackVar SaplTypedVar
68

69
unpackBindVar  :: !SaplLetDef -> SaplTypedVar
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
70
unpackBindExpr :: !SaplLetDef -> SaplTerm
71
unpackConsName :: !SaplPattern -> Maybe String
72
toStrictBind   :: !SaplLetDef -> SaplLetDef
73

74 75
isConsPattern    :: !SaplPattern -> Bool
isDefaultPattern :: !SaplPattern -> Bool
76