code-conjure-0.5.14: synthesize Haskell functions out of partial definitions
Copyright(c) 2021-2024 Rudy Matela
License3-Clause BSD (see the file LICENSE)
MaintainerRudy Matela <rudy@matela.com.br>
Safe HaskellSafe-Inferred
LanguageHaskell2010

Conjure.Red

Description

This module is part of Conjure.

This defines functions that deal with recursive descent and deconstructions

Synopsis

Documentation

conjureIsDeconstruction :: Conjurable f => f -> Int -> Expr -> Bool Source #

Checks if an expression is a deconstruction.

There should be a single hole in the expression.

It should decrease the size of all arguments that have a size greater than 0.

descends :: (Expr -> Expr -> Bool) -> Expr -> Expr -> Bool Source #

Returns whether a non-empty subset of arguments descends arguments by deconstruction.

> descends isDec (xxs -++- yys) (xxs -++- tail' yys)
True
> descends isDec (xxs -++- yys) (xxs -++- yys)
False
> descends isDec (xxs -++- yys) (head' xxs -:- tail xxs  -++-  head' yys -:- tail yys)
False

candidateDeconstructionsFrom :: Expr -> [Expr] Source #

Compute candidate deconstructions from an Expr.

This is used in the implementation of candidateDefnsC followed by conjureIsDeconstruction.

> candidateDeconstructionsFrom (xx `mod'` yy)
[ _ `mod` y
, x `mod` _
]

To be constrasted with candidateDeconstructionsFromHoled.

candidateDeconstructionsFromHoled :: Expr -> [Expr] Source #

Compute candidate deconstructions from an Expr.

This is used in the implementation of candidateExprs followed by conjureIsDeconstruction.

This is similar to canonicalVariations but always leaves a hole of the same return type as the given expression.

> candidateDeconstructionsFrom (i_ `mod'` i_)
[ _ `mod` x
, x `mod` _
]

To be contrasted with candidateDeconstructionsFrom