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

Safe HaskellSafe-Inferred

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 nSource

Empty arities context.

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

Extend map with some binders and their arities.

getArity :: Ord n => Arities n -> Bound n -> Maybe IntSource

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 nSource

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 IntSource

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 IntSource

Get the arity of an expression.