IRTS.Defunctionalise

idris-1.3.4: Functional Programming Language with Dependent Types

License | BSD3
Maintainer | The Idris Community.
Safe Haskell | None
Language | Haskell2010

IRTS.Defunctionalise

Description

To defunctionalise:

1. Create a data constructor for each function
2. Create a data constructor for each underapplication of a function
3. Convert underapplications to their corresponding constructors
4. Create an EVAL function which calls the appropriate function for data constructors created as part of step 1
5. Create an APPLY function which adds an argument to each underapplication (or calls APPLY again for an exact application)
6. Wrap overapplications in chains of APPLY
7. Wrap unknown applications (i.e. applications of local variables) in chains of APPLY
8. Add explicit EVAL to case, primitives, and foreign calls

Synopsis

- declare :: Int -> [(Name, Int, EvalApply DAlt)] -> [(Name, DDecl)]
- data DExp
  - = DV Name
  - | DApp Bool Name [DExp]
  - | DLet Name DExp DExp
  - | DUpdate Name DExp
  - | DProj DExp Int
  - | DC (Maybe Name) Int Name [DExp]
  - | DCase CaseType DExp [DAlt]
  - | DChkCase DExp [DAlt]
  - | DConst Const
  - | DForeign FDesc FDesc [(FDesc, DExp)]
  - | DOp PrimFn [DExp]
  - | DNothing
  - | DError String
- data DAlt
  - = DConCase Int Name [Name] DExp
  - | DConstCase Const DExp
  - | DDefaultCase DExp
- data DDecl
  - = DFun Name [Name] DExp
  - | DConstructor Name Int Int
- type DDefs = Ctxt DDecl
- defunctionalise :: Int -> LDefs -> DDefs
- addApps :: LDefs -> (Name, LDecl) -> State ([Name], [(Name, Int)]) (Name, DDecl)
- toCons :: [Name] -> (Name, Int) -> [(Name, Int, EvalApply DAlt)]
- getFn :: [(Name, LDecl)] -> [(Name, Int)]
- toConsA :: [(Name, Int)] -> (Name, Int) -> [(Name, Int, EvalApply DAlt)]
- mkEval :: [(Name, Int, EvalApply DAlt)] -> (Name, DDecl)
- mkApply :: [(Name, Int, EvalApply DAlt)] -> (Name, DDecl)
- mkApply2 :: [(Name, Int, EvalApply DAlt)] -> (Name, DDecl)
- eEVAL :: DExp -> DExp
- mkUnderCon :: Name -> Int -> Name
- mkFnCon :: Show a => a -> Name
- data EvalApply a
  - = EvalCase (Name -> a)
  - | ApplyCase a
  - | Apply2Case a
- genArgs :: Int -> [Name]
- mkApplyCase :: Name -> Int -> Int -> [(Name, Int, EvalApply DAlt)]
- mkBigCase :: p -> Int -> DExp -> [DAlt] -> DExp
- groupsOf :: Int -> [DAlt] -> [[DAlt]]
- dumpDefuns :: DDefs -> String
- module IRTS.Lang

# Documentation

declare :: Int -> [(Name, Int, EvalApply DAlt)] -> [(Name, DDecl)] #

data DExp #

Constructors

DV Name |
DApp Bool Name [DExp] |
DLet Name DExp DExp |
DUpdate Name DExp |
DProj DExp Int |
DC (Maybe Name) Int Name [DExp] |
DCase CaseType DExp [DAlt] |
DChkCase DExp [DAlt] |
DConst Const |
DForeign FDesc FDesc [(FDesc, DExp)] |
DOp PrimFn [DExp] |
DNothing |
DError String |

#### Instances

Instances details

ToJSON DExp # |
Instance details Defined in IRTS.Portable Methods toJSON :: DExp -> Value # toEncoding :: DExp -> Encoding # toJSONList :: [DExp] -> Value # toEncodingList :: [DExp] -> Encoding # omitField :: DExp -> Bool #
Show DExp # |
Instance details Defined in IRTS.Defunctionalise Methods showsPrec :: Int -> DExp -> ShowS # show :: DExp -> String # showList :: [DExp] -> ShowS #
Eq DExp # |
Instance details Defined in IRTS.Defunctionalise Methods (==) :: DExp -> DExp -> Bool # (/=) :: DExp -> DExp -> Bool #

data DAlt #

Constructors

DConCase Int Name [Name] DExp |
DConstCase Const DExp |
DDefaultCase DExp |

#### Instances

Instances details

ToJSON DAlt # |
Instance details Defined in IRTS.Portable Methods toJSON :: DAlt -> Value # toEncoding :: DAlt -> Encoding # toJSONList :: [DAlt] -> Value # toEncodingList :: [DAlt] -> Encoding # omitField :: DAlt -> Bool #
Show DAlt # |
Instance details Defined in IRTS.Defunctionalise Methods showsPrec :: Int -> DAlt -> ShowS # show :: DAlt -> String # showList :: [DAlt] -> ShowS #
Eq DAlt # |
Instance details Defined in IRTS.Defunctionalise Methods (==) :: DAlt -> DAlt -> Bool # (/=) :: DAlt -> DAlt -> Bool #

data DDecl #

Constructors

DFun Name [Name] DExp |
DConstructor Name Int Int |

#### Instances

Instances details

ToJSON DDecl # |
Instance details Defined in IRTS.Portable Methods toJSON :: DDecl -> Value # toEncoding :: DDecl -> Encoding # toJSONList :: [DDecl] -> Value # toEncodingList :: [DDecl] -> Encoding # omitField :: DDecl -> Bool #
Show DDecl # |
Instance details Defined in IRTS.Defunctionalise Methods showsPrec :: Int -> DDecl -> ShowS # show :: DDecl -> String # showList :: [DDecl] -> ShowS #
Eq DDecl # |
Instance details Defined in IRTS.Defunctionalise Methods (==) :: DDecl -> DDecl -> Bool # (/=) :: DDecl -> DDecl -> Bool #

type DDefs = Ctxt DDecl #

defunctionalise :: Int -> LDefs -> DDefs #

addApps :: LDefs -> (Name, LDecl) -> State ([Name], [(Name, Int)]) (Name, DDecl) #

toCons :: [Name] -> (Name, Int) -> [(Name, Int, EvalApply DAlt)] #

getFn :: [(Name, LDecl)] -> [(Name, Int)] #

toConsA :: [(Name, Int)] -> (Name, Int) -> [(Name, Int, EvalApply DAlt)] #

mkEval :: [(Name, Int, EvalApply DAlt)] -> (Name, DDecl) #

mkApply :: [(Name, Int, EvalApply DAlt)] -> (Name, DDecl) #

mkApply2 :: [(Name, Int, EvalApply DAlt)] -> (Name, DDecl) #

eEVAL :: DExp -> DExp #

mkUnderCon :: Name -> Int -> Name #

mkFnCon :: Show a => a -> Name #

data EvalApply a #

Constructors

EvalCase (Name -> a) |
ApplyCase a |
Apply2Case a |

genArgs :: Int -> [Name] #

mkApplyCase :: Name -> Int -> Int -> [(Name, Int, EvalApply DAlt)] #

mkBigCase :: p -> Int -> DExp -> [DAlt] -> DExp #

Divide up a large case expression so that each has a maximum of `max` branches

groupsOf :: Int -> [DAlt] -> [[DAlt]] #

dumpDefuns :: DDefs -> String #

module IRTS.Lang