[#314] move `#=` to Indigo's frontend and make it a synonym for `//->`

Problem: we had a `#=` operator that was a synonym of `/->`, but the
former is no longer usable and the latter is not used in favor of
`//->` (in the frontend).

Solution: `move `#=` to Indigo's frontend and make it a synonym for
`//->` instead.
parent 60725979
Pipeline #181277615 passed with stages
in 3 minutes and 57 seconds
Unreleased
==========
<!-- Append new entries here -->
* [!542](https://gitlab.com/morley-framework/morley/-/merge_requests/542)
Use `#=` as a synonym for `//->`.
0.1.0.0
=======
......
......@@ -7,8 +7,7 @@
-- | High level statements of Indigo language.
module Indigo.Backend.Case
( (#=)
, caseRec
( caseRec
, entryCaseRec
, entryCaseSimpleRec
......@@ -71,11 +70,6 @@ instance
liftClear' @(ClassifyReturnValue retBr) @retBr @(x & inp) @inp L.drop
)
-- | An alias for '/->' to use when the body is a lambda so that the
-- whole thing won't have multiple arrows.
(#=) :: CaseArrow name body clause => Label name -> body -> clause
(#=) a b = a /-> b
-- This constraint is shared by all @case*@ functions.
type CaseCommonF f dt guard ret clauses =
( guard :~> dt
......
......@@ -45,6 +45,7 @@ module Indigo.Frontend.Language
, entryCaseRec
, entryCaseSimple
, (//->)
, (#=)
-- * Scope
, scope
......@@ -430,12 +431,32 @@ entryCaseSimple
-> IndigoM (RetVars ret)
entryCaseSimple g = oneIndigoM . EntryCaseSimple g . recFromTuple @clauses
{-# DEPRECATED (//->) "use '#=' instead" #-}
-- | An alias for '#=' kept only for backward compatibility.
(//->)
:: ( CaseArrow name (Var x -> IndigoAnyOut x ret)
(IndigoCaseClauseL ret ('CaseClauseParam ctor ('OneField x)))
, ScopeCodeGen retBr
, ret ~ RetExprs retBr
, RetOutStack ret ~ RetOutStack retBr
, KnownValue x
, name ~ (AppendSymbol "c" ctor)
)
=> Label name
-> (Var x -> IndigoM retBr)
-> IndigoMCaseClauseL IndigoM ret ('CaseClauseParam ctor ('OneField x))
(//->) cName b = OneFieldIndigoMCaseClauseL cName b
infixr 0 //->
-- | Use this instead of '/->'.
--
-- This operator is like '/->' but wraps a body into 'IndigoAnyOut',
-- which is needed for two reasons: to allow having any output stack
-- and to allow returning not exactly the same values.
(//->)
--
-- It has the added benefit of not being an arrow, so in case the body of the
-- clause is a lambda there won't be several.
(#=)
:: ( CaseArrow name (Var x -> IndigoAnyOut x ret)
(IndigoCaseClauseL ret ('CaseClauseParam ctor ('OneField x)))
, ScopeCodeGen retBr
......@@ -447,8 +468,8 @@ entryCaseSimple g = oneIndigoM . EntryCaseSimple g . recFromTuple @clauses
=> Label name
-> (Var x -> IndigoM retBr)
-> IndigoMCaseClauseL IndigoM ret ('CaseClauseParam ctor ('OneField x))
(//->) cName b = OneFieldIndigoMCaseClauseL cName b
infixr 0 //->
(#=) cName b = OneFieldIndigoMCaseClauseL cName b
infixr 0 #=
----------------------------------------------------------------------------
-- Scope & Functions
......
......@@ -73,14 +73,14 @@ contractCaseLorentz = compileIndigoContract $ \param -> scope do
-- 2. branches can return not exactly the same types
--- it's useful when you have case bodies in-place, like
-- case_ param $
-- ( #cSomething1 //-> const $ return (5 int)
-- , #cSomething2 //-> (\var -> return (10 +. var))
-- , #cSomething3 //-> return var)
-- ( #cSomething1 #= const $ return (5 int)
-- , #cSomething2 #= (\var -> return (10 +. var))
-- , #cSomething3 #= return var)
-- Pay attention, that all three branches have different return types
-- but they all correspond to the same expression 'Expr Integer'.
_flag <- case_ param $
( #cDSub //-> doSub storageVar
, #cDAdd //-> doAdd storageVar
( #cDSub #= doSub storageVar
, #cDAdd #= doAdd storageVar
)
return ()
......
......@@ -57,7 +57,7 @@ this and have each branch `return` nothing (aka `()`), but in this case we want
to perform a check based on `param` and have its result returned.
Let's look at the definition for the first branch, which is to say what follows
the `//->` for `#cIsZero`:
the `#=` for `#cIsZero`:
{!haskell 24-25 src/Indigo/Tutorial/Statements/Control.hs!}
......
......@@ -20,8 +20,8 @@ instance ParameterHasEntrypoints IncrementIf where
functionsContract :: IndigoContract IncrementIf Natural
functionsContract param = defContract do
result <- case_ param $
( #cIsZero //-> checkZero
, #cHasDigitOne //-> checkHasDigitOne
( #cIsZero #= checkZero
, #cHasDigitOne #= checkHasDigitOne
)
updateStorage result
......
......@@ -20,8 +20,8 @@ instance ParameterHasEntrypoints IncrementIf where
errorsContract :: IndigoContract IncrementIf Natural
errorsContract param = defContract do
case_ param $
( #cIsZero //-> checkZero
, #cHasDigitOne //-> checkHasDigitOne
( #cIsZero #= checkZero
, #cHasDigitOne #= checkHasDigitOne
)
incrementStorage
......
......@@ -21,9 +21,9 @@ controlContract :: IndigoContract IncrementIf Natural
controlContract param = defContract do
base <- new$ 10 nat
result <- case_ param $
( #cIsZero //-> \val -> do
( #cIsZero #= \val -> do
return (val == 0 int)
, #cHasDigitOne //-> \val -> do
, #cHasDigitOne #= \val -> do
checkRes <- new$ False
while (val > base && checkRes == False) do
val =: val / base
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment