ddc-core-simpl-0.4.2.1: Disciplined Disciple Compiler code transformations.

Safe HaskellSafe
LanguageHaskell98

DDC.Core.Analysis.Arity

Contents

Description

Slurp out arities of function bindings. and infer arities for primitives based on their types.

For function bindings the arity is the number of outer-most lambdas in the definition.

For primitives, the arity is the number of function constructors in its type.

Synopsis

Arities map

type Arities n = (Map n Int, [Int]) Source

Arities of named and anonymous bindings.

emptyArities :: Ord n => Arities n Source

Empty arities context.

extendsArities :: Ord n => Arities n -> [(Bind n, Int)] -> Arities n Source

Extend map with some binders and their arities.

getArity :: Ord n => Arities n -> Bound n -> Maybe Int Source

Look up a binder's arity from the arity map or determine it from its type in the case of primops.

Arity analysis

aritiesOfModule :: Ord n => Module a n -> Arities n Source

Slurp out arities of imports and top-level bindings from a module.

aritiesOfLets :: Ord n => Lets a n -> Maybe [(Bind n, Int)] Source

Get the arities of a Lets

aritiesOfPat :: Ord n => Pat n -> [(Bind n, Int)] Source

Retrieve binders from case pattern, so we can extend the arity context. We don't know anything about their values, so record as 0.

arityFromType :: Ord n => Type n -> Maybe Int Source

Determine the arity of an expression by looking at its type. Count all the function arrows, and foralls.

arityOfExp :: Ord n => Exp a n -> Maybe Int Source

Get the arity of an expression.