├── CLAUDE.md ├── .golden ├── Malgo.Sequent.Eval │ ├── Fib │ │ ├── actual │ │ └── golden │ ├── DataDef │ │ ├── actual │ │ └── golden │ ├── Null │ │ ├── actual │ │ └── golden │ ├── Ones │ │ ├── actual │ │ └── golden │ ├── Seq │ │ ├── actual │ │ └── golden │ ├── Test0 │ │ ├── actual │ │ └── golden │ ├── Test1 │ │ ├── actual │ │ └── golden │ ├── Test2 │ │ ├── actual │ │ └── golden │ ├── Test3 │ │ ├── actual │ │ └── golden │ ├── Test6 │ │ ├── actual │ │ └── golden │ ├── TestDot │ │ ├── actual │ │ └── golden │ ├── TestLet │ │ ├── actual │ │ └── golden │ ├── ZeroArgs │ │ ├── actual │ │ └── golden │ ├── Bool │ │ ├── actual │ │ └── golden │ ├── CStyleDataDef │ │ ├── actual │ │ └── golden │ ├── Double │ │ ├── actual │ │ └── golden │ ├── Echo │ │ ├── actual │ │ └── golden │ ├── Eventually │ │ ├── actual │ │ └── golden │ ├── FibCopattern │ │ ├── actual │ │ └── golden │ ├── NestedMatch │ │ ├── actual │ │ └── golden │ ├── Pattern │ │ ├── actual │ │ └── golden │ ├── Primitive │ │ ├── actual │ │ └── golden │ ├── RecordTest │ │ ├── actual │ │ └── golden │ ├── RightAssoc │ │ ├── actual │ │ └── golden │ ├── Show │ │ ├── actual │ │ └── golden │ ├── ShowSimple │ │ ├── actual │ │ └── golden │ ├── TestList │ │ ├── actual │ │ └── golden │ ├── TuplePattern │ │ ├── actual │ │ └── golden │ ├── Undefined │ │ ├── actual │ │ └── golden │ ├── CStyleApply │ │ ├── actual │ │ └── golden │ ├── CStyleTypeSynonym │ │ ├── actual │ │ └── golden │ ├── DeferLaw │ │ ├── actual │ │ └── golden │ ├── EmptyArguments │ │ ├── actual │ │ └── golden │ ├── EvenOdd │ │ ├── actual │ │ └── golden │ ├── Factorial │ │ ├── actual │ │ └── golden │ ├── FieldPrefix │ │ ├── actual │ │ └── golden │ ├── FuncOverUnboxed │ │ ├── actual │ │ └── golden │ ├── RecordFieldAccess │ │ ├── actual │ │ └── golden │ ├── TestPatSynRecon │ │ ├── actual │ │ └── golden │ ├── TestPolySynonym │ │ ├── actual │ │ └── golden │ ├── ToplevelVariable │ │ ├── actual │ │ └── golden │ ├── TypeAnnotation │ │ ├── actual │ │ └── golden │ ├── With │ │ ├── actual │ │ └── golden │ ├── InlineFunction │ │ ├── actual │ │ └── golden │ ├── Pragma │ │ ├── actual │ │ └── golden │ ├── SameImport │ │ ├── actual │ │ └── golden │ ├── TestArithDouble │ │ ├── actual │ │ └── golden │ ├── TestEither │ │ ├── actual │ │ └── golden │ ├── TestNestedLetFunc │ │ ├── actual │ │ └── golden │ ├── EmptyConstructor │ │ ├── actual │ │ └── golden │ ├── HelloBoxed │ │ ├── actual │ │ └── golden │ ├── HelloImport │ │ ├── actual │ │ └── golden │ ├── ToplevelVariableNoImport │ │ ├── actual │ │ └── golden │ ├── TypeSynonym │ │ ├── actual │ │ └── golden │ ├── UseModule │ │ ├── actual │ │ └── golden │ ├── TestExplicitModule │ │ ├── actual │ │ └── golden │ └── Punctuate │ │ ├── actual │ │ └── golden ├── Malgo.Rename │ ├── error │ │ ├── DuplicateDef │ │ │ ├── actual │ │ │ └── golden │ │ ├── NotImported │ │ │ ├── actual │ │ │ └── golden │ │ ├── UndefinedType │ │ │ ├── actual │ │ │ └── golden │ │ ├── UndefinedVariable │ │ │ ├── actual │ │ │ └── golden │ │ ├── UndefinedTypeVariable │ │ │ ├── actual │ │ │ └── golden │ │ └── NotQualifiedImported │ │ │ ├── actual │ │ │ └── golden │ ├── Echo │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── SameImport │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── TestExplicitModule │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── Double │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── Pattern │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── Primitive │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── EmptyConstructor │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── Undefined │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── CStyleDataDef │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── EmptyArguments │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── CStyleTypeSynonym │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── DeferLaw │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── Pragma │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── TypeAnnotation │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── HelloBoxed │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── Seq │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── TestList │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ └── HelloImport │ │ └── sexpr │ │ ├── actual │ │ └── golden ├── Malgo.Parser │ ├── error │ │ ├── InvalidOperator │ │ │ ├── actual │ │ │ └── golden │ │ ├── InvalidIdentifier │ │ │ ├── actual │ │ │ └── golden │ │ ├── MissingEqualInDef │ │ │ ├── actual │ │ │ └── golden │ │ ├── MissingImportInForeign │ │ │ ├── actual │ │ │ └── golden │ │ └── MissingParentheses │ │ │ ├── actual │ │ │ └── golden │ ├── Echo │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── CStyleTypeSynonym │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── Double │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── Pattern │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── CStyleDataDef │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── SameImport │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── TestExplicitModule │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── DeferLaw │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── EmptyConstructor │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── TestList │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── Undefined │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── Primitive │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── EmptyArguments │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── TestPolySynonym │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── TypeAnnotation │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── Pragma │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── HelloBoxed │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── TestNestedLetFunc │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── Seq │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── TuplePattern │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── UseModule │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── DataDef │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── TestDot │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── HelloImport │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── RecordFieldAccess │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ ├── Test0 │ │ └── sexpr │ │ │ ├── actual │ │ │ └── golden │ └── Test2 │ │ └── sexpr │ │ ├── actual │ │ └── golden ├── Malgo.Sequent.ToFun │ ├── CStyleTypeSynonym │ │ ├── actual │ │ └── golden │ ├── Echo │ │ ├── actual │ │ └── golden │ ├── TestExplicitModule │ │ ├── actual │ │ └── golden │ ├── SameImport │ │ ├── actual │ │ └── golden │ ├── Double │ │ ├── actual │ │ └── golden │ ├── Primitive │ │ ├── actual │ │ └── golden │ ├── Pattern │ │ ├── actual │ │ └── golden │ ├── TypeAnnotation │ │ ├── actual │ │ └── golden │ ├── DeferLaw │ │ ├── actual │ │ └── golden │ ├── Undefined │ │ ├── actual │ │ └── golden │ ├── TestDot │ │ ├── actual │ │ └── golden │ ├── Ones │ │ ├── actual │ │ └── golden │ ├── FuncOverUnboxed │ │ ├── actual │ │ └── golden │ ├── EmptyConstructor │ │ ├── actual │ │ └── golden │ ├── HelloImport │ │ ├── actual │ │ └── golden │ ├── TuplePattern │ │ ├── actual │ │ └── golden │ ├── Seq │ │ ├── actual │ │ └── golden │ ├── Test2 │ │ ├── actual │ │ └── golden │ └── TestPolySynonym │ │ ├── actual │ │ └── golden └── Malgo.Sequent.ToCore │ ├── CStyleTypeSynonym │ ├── actual │ ├── golden │ ├── flat │ │ ├── actual │ │ └── golden │ └── join │ │ ├── actual │ │ └── golden │ ├── Echo │ ├── actual │ ├── golden │ └── flat │ │ ├── actual │ │ └── golden │ ├── SameImport │ ├── actual │ └── golden │ ├── TestExplicitModule │ ├── actual │ └── golden │ ├── Pattern │ ├── actual │ └── golden │ └── Double │ ├── actual │ └── golden ├── weeder.toml ├── .gitattributes ├── .github ├── copilot-instructions.md ├── dependabot.yml ├── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── disabled-workflows │ └── update-flake-lock.yml └── workflows │ └── upload-sbom.yml ├── test ├── Spec.hs ├── testcases │ └── malgo │ │ ├── error │ │ ├── ErrorOnlySig.mlg │ │ ├── ErrorInvalidIdent.mlg │ │ ├── ErrorKind2.mlg │ │ ├── ErrorKind.mlg │ │ ├── ErrorRigidType.mlg │ │ ├── ErrorKind3.mlg │ │ ├── QualifiedImport.mlg │ │ ├── InvalidPattern.mlg │ │ ├── StringPatIsNotSupported.mlg │ │ ├── NeedSpaceDot.mlg │ │ ├── ConstructorArity.mlg │ │ ├── NonExhaustive.mlg │ │ ├── InferEither.mlg │ │ └── ErrorPatSynRecon.mlg │ │ ├── Primitive.mlg │ │ ├── TestNestedLetFunc.mlg │ │ ├── TestExplicitModule.mlg │ │ ├── Echo.mlg │ │ ├── Double.mlg │ │ ├── TypeAnnotation.mlg │ │ ├── Test2.mlg │ │ ├── Test1.mlg │ │ ├── Pattern.mlg │ │ ├── TestList.mlg │ │ ├── SameImport.mlg │ │ ├── TestDot.mlg │ │ ├── HelloImport.mlg │ │ ├── DeferLaw.mlg │ │ ├── Ones.mlg │ │ ├── Test6.mlg │ │ ├── Test0.mlg │ │ ├── ForallType.mlg.disabled │ │ ├── FuncOverUnboxed.mlg │ │ ├── DataDef.mlg │ │ ├── ZeroArgs.mlg │ │ ├── TuplePattern.mlg │ │ ├── Undefined.mlg │ │ ├── Seq.mlg │ │ ├── UseModule.mlg │ │ ├── Bool.mlg │ │ ├── RecordFieldAccess.mlg │ │ ├── Test3.mlg │ │ ├── TestLet.mlg │ │ ├── EvenOdd.mlg │ │ ├── EmptyConstructor.mlg │ │ ├── Pragma.mlg │ │ ├── HelloBoxed.mlg │ │ ├── TestPolySynonym.mlg │ │ ├── CStyleDataDef.mlg │ │ ├── RecordTest.mlg │ │ ├── TestPatSynRecon.mlg │ │ ├── TypeSynonym.mlg │ │ ├── CStyleTypeSynonym.mlg │ │ ├── ToplevelVariable.mlg │ │ ├── Fib.mlg │ │ ├── EmptyArguments.mlg │ │ ├── Factorial.mlg │ │ ├── InlineFunction.mlg │ │ ├── FibCopattern.mlg │ │ ├── With.mlg │ │ ├── CStyleApply.mlg │ │ ├── TestArithDouble.mlg │ │ ├── Punctuate.mlg │ │ ├── FieldPrefix.mlg │ │ ├── TestEither.mlg │ │ ├── Null.mlg │ │ ├── ShowSimple.mlg │ │ ├── Show.mlg │ │ └── RightAssoc.mlg └── Malgo │ ├── RenameSpec │ └── errors │ │ ├── NotImported.mlg │ │ ├── UndefinedVariable.mlg │ │ ├── DuplicateDef.mlg │ │ ├── NotQualifiedImported.mlg │ │ ├── UndefinedType.mlg │ │ └── UndefinedTypeVariable.mlg │ └── ParserSpec │ └── errors │ ├── MissingImportInForeign.mlg │ ├── MissingEqualInDef.mlg │ ├── MissingParentheses.mlg │ ├── InvalidIdentifier.mlg │ └── InvalidOperator.mlg ├── Setup.hs ├── hoogle.sh ├── src └── Malgo │ ├── Rename.hs │ ├── Monad.hs │ └── Rename │ └── RnState.hs ├── examples └── malgo │ ├── Hello.mlg │ ├── Cast.mlg │ ├── String.mlg │ ├── Record.mlg │ ├── Fib.mlg │ ├── Tarai.mlg │ ├── Infixing.mlg │ ├── Either.mlg │ ├── LazyList.mlg │ ├── List.mlg │ └── Vector.mlg ├── .claude └── settings.json ├── renovate.json ├── hie.yaml ├── wiki ├── 2025-09-06-empty-arguments.md └── 2025-09-04-empty-arguments.md ├── cabal.project ├── .pinact.yaml ├── .gitignore └── .devcontainer ├── post-create.sh ├── Dockerfile └── devcontainer.json /CLAUDE.md: -------------------------------------------------------------------------------- 1 | AGENTS.md -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Fib/actual: -------------------------------------------------------------------------------- 1 | 8 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Fib/golden: -------------------------------------------------------------------------------- 1 | 8 -------------------------------------------------------------------------------- /weeder.toml: -------------------------------------------------------------------------------- 1 | type-class-roots = true -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | .golden/** linguist-generated -------------------------------------------------------------------------------- /.github/copilot-instructions.md: -------------------------------------------------------------------------------- 1 | ../AGENTS.md -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/DataDef/actual: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/DataDef/golden: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Null/actual: -------------------------------------------------------------------------------- 1 | OK -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Null/golden: -------------------------------------------------------------------------------- 1 | OK -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Ones/actual: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Ones/golden: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Seq/actual: -------------------------------------------------------------------------------- 1 | 33 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Seq/golden: -------------------------------------------------------------------------------- 1 | 33 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Test0/actual: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Test0/golden: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Test1/actual: -------------------------------------------------------------------------------- 1 | True -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Test1/golden: -------------------------------------------------------------------------------- 1 | True -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Test2/actual: -------------------------------------------------------------------------------- 1 | OK -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Test2/golden: -------------------------------------------------------------------------------- 1 | OK -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Test3/actual: -------------------------------------------------------------------------------- 1 | OK -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Test3/golden: -------------------------------------------------------------------------------- 1 | OK -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Test6/actual: -------------------------------------------------------------------------------- 1 | OK -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Test6/golden: -------------------------------------------------------------------------------- 1 | OK -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TestDot/actual: -------------------------------------------------------------------------------- 1 | 2 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TestDot/golden: -------------------------------------------------------------------------------- 1 | 2 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TestLet/actual: -------------------------------------------------------------------------------- 1 | 33 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TestLet/golden: -------------------------------------------------------------------------------- 1 | 33 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/ZeroArgs/actual: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/ZeroArgs/golden: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Bool/actual: -------------------------------------------------------------------------------- 1 | True 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Bool/golden: -------------------------------------------------------------------------------- 1 | True 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/CStyleDataDef/actual: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/CStyleDataDef/golden: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Double/actual: -------------------------------------------------------------------------------- 1 | 3.14 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Double/golden: -------------------------------------------------------------------------------- 1 | 3.14 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Echo/actual: -------------------------------------------------------------------------------- 1 | Hello 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Echo/golden: -------------------------------------------------------------------------------- 1 | Hello 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Eventually/actual: -------------------------------------------------------------------------------- 1 | 1123 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Eventually/golden: -------------------------------------------------------------------------------- 1 | 1123 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/FibCopattern/actual: -------------------------------------------------------------------------------- 1 | 8 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/FibCopattern/golden: -------------------------------------------------------------------------------- 1 | 8 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/NestedMatch/actual: -------------------------------------------------------------------------------- 1 | OK -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/NestedMatch/golden: -------------------------------------------------------------------------------- 1 | OK -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Pattern/actual: -------------------------------------------------------------------------------- 1 | OK 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Pattern/golden: -------------------------------------------------------------------------------- 1 | OK 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Primitive/actual: -------------------------------------------------------------------------------- 1 | 42 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Primitive/golden: -------------------------------------------------------------------------------- 1 | 42 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/RecordTest/actual: -------------------------------------------------------------------------------- 1 | 42 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/RecordTest/golden: -------------------------------------------------------------------------------- 1 | 42 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/RightAssoc/actual: -------------------------------------------------------------------------------- 1 | OK -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/RightAssoc/golden: -------------------------------------------------------------------------------- 1 | OK -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Show/actual: -------------------------------------------------------------------------------- 1 | (1, 2) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Show/golden: -------------------------------------------------------------------------------- 1 | (1, 2) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/ShowSimple/actual: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/ShowSimple/golden: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TestList/actual: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TestList/golden: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TuplePattern/actual: -------------------------------------------------------------------------------- 1 | A -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TuplePattern/golden: -------------------------------------------------------------------------------- 1 | A -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Undefined/actual: -------------------------------------------------------------------------------- 1 | OK -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Undefined/golden: -------------------------------------------------------------------------------- 1 | OK -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/CStyleApply/actual: -------------------------------------------------------------------------------- 1 | 120 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/CStyleApply/golden: -------------------------------------------------------------------------------- 1 | 120 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/CStyleTypeSynonym/actual: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/CStyleTypeSynonym/golden: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/DeferLaw/actual: -------------------------------------------------------------------------------- 1 | Hello 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/DeferLaw/golden: -------------------------------------------------------------------------------- 1 | Hello 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/EmptyArguments/actual: -------------------------------------------------------------------------------- 1 | 01 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/EmptyArguments/golden: -------------------------------------------------------------------------------- 1 | 01 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/EvenOdd/actual: -------------------------------------------------------------------------------- 1 | True 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/EvenOdd/golden: -------------------------------------------------------------------------------- 1 | True 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Factorial/actual: -------------------------------------------------------------------------------- 1 | 120 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Factorial/golden: -------------------------------------------------------------------------------- 1 | 120 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/FieldPrefix/actual: -------------------------------------------------------------------------------- 1 | 0, 0 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/FieldPrefix/golden: -------------------------------------------------------------------------------- 1 | 0, 0 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/FuncOverUnboxed/actual: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/FuncOverUnboxed/golden: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/RecordFieldAccess/actual: -------------------------------------------------------------------------------- 1 | 42 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/RecordFieldAccess/golden: -------------------------------------------------------------------------------- 1 | 42 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TestPatSynRecon/actual: -------------------------------------------------------------------------------- 1 | 3 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TestPatSynRecon/golden: -------------------------------------------------------------------------------- 1 | 3 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TestPolySynonym/actual: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TestPolySynonym/golden: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/ToplevelVariable/actual: -------------------------------------------------------------------------------- 1 | OK2 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/ToplevelVariable/golden: -------------------------------------------------------------------------------- 1 | OK2 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TypeAnnotation/actual: -------------------------------------------------------------------------------- 1 | hoge -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TypeAnnotation/golden: -------------------------------------------------------------------------------- 1 | hoge -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/With/actual: -------------------------------------------------------------------------------- 1 | foofoofoofooend -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/With/golden: -------------------------------------------------------------------------------- 1 | foofoofoofooend -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/InlineFunction/actual: -------------------------------------------------------------------------------- 1 | 8 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/InlineFunction/golden: -------------------------------------------------------------------------------- 1 | 8 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Pragma/actual: -------------------------------------------------------------------------------- 1 | Hello, world 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Pragma/golden: -------------------------------------------------------------------------------- 1 | Hello, world 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/SameImport/actual: -------------------------------------------------------------------------------- 1 | Hello 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/SameImport/golden: -------------------------------------------------------------------------------- 1 | Hello 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TestArithDouble/actual: -------------------------------------------------------------------------------- 1 | 0.25 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TestArithDouble/golden: -------------------------------------------------------------------------------- 1 | 0.25 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TestEither/actual: -------------------------------------------------------------------------------- 1 | 12error 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TestEither/golden: -------------------------------------------------------------------------------- 1 | 12error 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TestNestedLetFunc/actual: -------------------------------------------------------------------------------- 1 | PASS -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TestNestedLetFunc/golden: -------------------------------------------------------------------------------- 1 | PASS -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/EmptyConstructor/actual: -------------------------------------------------------------------------------- 1 | EmptyUnit({}) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/EmptyConstructor/golden: -------------------------------------------------------------------------------- 1 | EmptyUnit({}) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/HelloBoxed/actual: -------------------------------------------------------------------------------- 1 | Hello, world 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/HelloBoxed/golden: -------------------------------------------------------------------------------- 1 | Hello, world 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/HelloImport/actual: -------------------------------------------------------------------------------- 1 | hello world 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/HelloImport/golden: -------------------------------------------------------------------------------- 1 | hello world 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/ToplevelVariableNoImport/actual: -------------------------------------------------------------------------------- 1 | OK2 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/ToplevelVariableNoImport/golden: -------------------------------------------------------------------------------- 1 | OK2 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TypeSynonym/actual: -------------------------------------------------------------------------------- 1 | hello world 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TypeSynonym/golden: -------------------------------------------------------------------------------- 1 | hello world 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/UseModule/actual: -------------------------------------------------------------------------------- 1 | Hello, world! 2 | 3 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/UseModule/golden: -------------------------------------------------------------------------------- 1 | Hello, world! 2 | 3 -------------------------------------------------------------------------------- /test/Spec.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_GHC -F -pgmF hspec-discover #-} 2 | -------------------------------------------------------------------------------- /Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | 3 | main = defaultMain 4 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TestExplicitModule/actual: -------------------------------------------------------------------------------- 1 | Hello, world 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/TestExplicitModule/golden: -------------------------------------------------------------------------------- 1 | Hello, world 2 | -------------------------------------------------------------------------------- /test/testcases/malgo/error/ErrorOnlySig.mlg: -------------------------------------------------------------------------------- 1 | def foo : Int32# -> () 2 | -------------------------------------------------------------------------------- /test/testcases/malgo/error/ErrorInvalidIdent.mlg: -------------------------------------------------------------------------------- 1 | def let = {x f -> f x} 2 | -------------------------------------------------------------------------------- /test/Malgo/RenameSpec/errors/NotImported.mlg: -------------------------------------------------------------------------------- 1 | def main = { 2 | putStr (getContents ()) 3 | } 4 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Punctuate/actual: -------------------------------------------------------------------------------- 1 | SList [Symbol x, SList [Symbol y, SList [Symbol z]]] 2 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.Eval/Punctuate/golden: -------------------------------------------------------------------------------- 1 | SList [Symbol x, SList [Symbol y, SList [Symbol z]]] 2 | -------------------------------------------------------------------------------- /test/testcases/malgo/error/ErrorKind2.mlg: -------------------------------------------------------------------------------- 1 | data A = A 2 | def f : A a -> A a 3 | def f = { x -> x } 4 | -------------------------------------------------------------------------------- /test/testcases/malgo/error/ErrorKind.mlg: -------------------------------------------------------------------------------- 1 | def id : a -> a 2 | def id = {x -> x} 3 | def main = { id 42# } 4 | -------------------------------------------------------------------------------- /test/Malgo/RenameSpec/errors/UndefinedVariable.mlg: -------------------------------------------------------------------------------- 1 | def fun = { x -> y } 2 | 3 | def main = { 4 | fun () 5 | } -------------------------------------------------------------------------------- /test/testcases/malgo/error/ErrorRigidType.mlg: -------------------------------------------------------------------------------- 1 | def apply : (a -> b) -> b -> a 2 | def apply = { f x -> f x } 3 | -------------------------------------------------------------------------------- /test/Malgo/ParserSpec/errors/MissingImportInForeign.mlg: -------------------------------------------------------------------------------- 1 | foreign malgo_newline : () -> () 2 | 3 | def main = { 4 | malgo_newline () 5 | } -------------------------------------------------------------------------------- /test/Malgo/RenameSpec/errors/DuplicateDef.mlg: -------------------------------------------------------------------------------- 1 | def fun = { x -> x } 2 | 3 | def fun = { x -> x } 4 | 5 | def main = { 6 | fun () 7 | } -------------------------------------------------------------------------------- /test/Malgo/ParserSpec/errors/MissingEqualInDef.mlg: -------------------------------------------------------------------------------- 1 | foreign import malgo_newline : () -> () 2 | 3 | def main { 4 | malgo_newline () 5 | } 6 | -------------------------------------------------------------------------------- /test/Malgo/ParserSpec/errors/MissingParentheses.mlg: -------------------------------------------------------------------------------- 1 | foreign import malgo_newline : () -> () 2 | 3 | def main = { 4 | malgo_newline ( 5 | } 6 | -------------------------------------------------------------------------------- /test/testcases/malgo/error/ErrorKind3.mlg: -------------------------------------------------------------------------------- 1 | def f : a -> Int32# 2 | def f = { x -> 42# } 3 | 4 | def main = { 5 | f 43#; 6 | () 7 | } 8 | 9 | -------------------------------------------------------------------------------- /.golden/Malgo.Rename/error/DuplicateDef/actual: -------------------------------------------------------------------------------- 1 | test/Malgo/RenameSpec/errors/DuplicateDef.mlg: line 3, column 1 - line 5, column 1: 2 | Duplicate name: 'fun' -------------------------------------------------------------------------------- /.golden/Malgo.Rename/error/DuplicateDef/golden: -------------------------------------------------------------------------------- 1 | test/Malgo/RenameSpec/errors/DuplicateDef.mlg: line 3, column 1 - line 5, column 1: 2 | Duplicate name: 'fun' -------------------------------------------------------------------------------- /.golden/Malgo.Rename/error/NotImported/actual: -------------------------------------------------------------------------------- 1 | test/Malgo/RenameSpec/errors/NotImported.mlg: line 2, column 3 - line 2, column 10: 2 | Not in scope: 'putStr' -------------------------------------------------------------------------------- /.golden/Malgo.Rename/error/NotImported/golden: -------------------------------------------------------------------------------- 1 | test/Malgo/RenameSpec/errors/NotImported.mlg: line 2, column 3 - line 2, column 10: 2 | Not in scope: 'putStr' -------------------------------------------------------------------------------- /.golden/Malgo.Rename/error/UndefinedType/actual: -------------------------------------------------------------------------------- 1 | test/Malgo/RenameSpec/errors/UndefinedType.mlg: line 6, column 16 - line 6, column 23: 2 | Not in scope: 'String' -------------------------------------------------------------------------------- /.golden/Malgo.Rename/error/UndefinedType/golden: -------------------------------------------------------------------------------- 1 | test/Malgo/RenameSpec/errors/UndefinedType.mlg: line 6, column 16 - line 6, column 23: 2 | Not in scope: 'String' -------------------------------------------------------------------------------- /.golden/Malgo.Rename/error/UndefinedVariable/actual: -------------------------------------------------------------------------------- 1 | test/Malgo/RenameSpec/errors/UndefinedVariable.mlg: line 1, column 18 - line 1, column 20: 2 | Not in scope: 'y' -------------------------------------------------------------------------------- /.golden/Malgo.Rename/error/UndefinedVariable/golden: -------------------------------------------------------------------------------- 1 | test/Malgo/RenameSpec/errors/UndefinedVariable.mlg: line 1, column 18 - line 1, column 20: 2 | Not in scope: 'y' -------------------------------------------------------------------------------- /hoogle.sh: -------------------------------------------------------------------------------- 1 | cabal haddock --haddock-internal --haddock-quickjump --haddock-hoogle --haddock-html 2 | 3 | hoogle generate --local 4 | 5 | hoogle server --local 6 | -------------------------------------------------------------------------------- /.golden/Malgo.Rename/error/UndefinedTypeVariable/actual: -------------------------------------------------------------------------------- 1 | test/Malgo/RenameSpec/errors/UndefinedTypeVariable.mlg: line 4, column 17 - line 4, column 18: 2 | Not in scope: 'a' -------------------------------------------------------------------------------- /.golden/Malgo.Rename/error/UndefinedTypeVariable/golden: -------------------------------------------------------------------------------- 1 | test/Malgo/RenameSpec/errors/UndefinedTypeVariable.mlg: line 4, column 17 - line 4, column 18: 2 | Not in scope: 'a' -------------------------------------------------------------------------------- /src/Malgo/Rename.hs: -------------------------------------------------------------------------------- 1 | module Malgo.Rename (module X) where 2 | 3 | import Malgo.Rename.Pass as X 4 | import Malgo.Rename.RnEnv as X 5 | import Malgo.Rename.RnState as X 6 | -------------------------------------------------------------------------------- /test/testcases/malgo/Primitive.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | def main = { printString# (toStringInt64# (addInt64# 40i64# 2i64#)) } 3 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/error/InvalidOperator/actual: -------------------------------------------------------------------------------- 1 | test/Malgo/ParserSpec/errors/InvalidOperator.mlg:5:10: 2 | | 3 | 5 | infix 4 (=>) 4 | | ^ 5 | unexpected '=' 6 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/error/InvalidOperator/golden: -------------------------------------------------------------------------------- 1 | test/Malgo/ParserSpec/errors/InvalidOperator.mlg:5:10: 2 | | 3 | 5 | infix 4 (=>) 4 | | ^ 5 | unexpected '=' 6 | -------------------------------------------------------------------------------- /.golden/Malgo.Rename/error/NotQualifiedImported/actual: -------------------------------------------------------------------------------- 1 | test/Malgo/RenameSpec/errors/NotQualifiedImported.mlg: line 8, column 3 - line 8, column 10: 2 | Not in scope: 'Prelude' -------------------------------------------------------------------------------- /.golden/Malgo.Rename/error/NotQualifiedImported/golden: -------------------------------------------------------------------------------- 1 | test/Malgo/RenameSpec/errors/NotQualifiedImported.mlg: line 8, column 3 - line 8, column 10: 2 | Not in scope: 'Prelude' -------------------------------------------------------------------------------- /test/testcases/malgo/TestNestedLetFunc.mlg: -------------------------------------------------------------------------------- 1 | foreign import malgo_print_string : String# -> () 2 | def main = { 3 | let f = {let y = {a -> ()} ()}; 4 | malgo_print_string "PASS"# 5 | } 6 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/error/InvalidIdentifier/actual: -------------------------------------------------------------------------------- 1 | test/Malgo/ParserSpec/errors/InvalidIdentifier.mlg:7:5: 2 | | 3 | 7 | def let : String -> () 4 | | ^ 5 | unexpected 'l' 6 | expecting '(' 7 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/error/InvalidIdentifier/golden: -------------------------------------------------------------------------------- 1 | test/Malgo/ParserSpec/errors/InvalidIdentifier.mlg:7:5: 2 | | 3 | 7 | def let : String -> () 4 | | ^ 5 | unexpected 'l' 6 | expecting '(' 7 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/error/MissingEqualInDef/actual: -------------------------------------------------------------------------------- 1 | test/Malgo/ParserSpec/errors/MissingEqualInDef.mlg:3:10: 2 | | 3 | 3 | def main { 4 | | ^ 5 | unexpected '{' 6 | expecting ':' or '=' 7 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/error/MissingEqualInDef/golden: -------------------------------------------------------------------------------- 1 | test/Malgo/ParserSpec/errors/MissingEqualInDef.mlg:3:10: 2 | | 3 | 3 | def main { 4 | | ^ 5 | unexpected '{' 6 | expecting ':' or '=' 7 | -------------------------------------------------------------------------------- /examples/malgo/Hello.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../runtime/malgo/Prelude.mlg" 3 | 4 | def main = { 5 | putStrLn "Hello, world!" 6 | } 7 | -------------------------------------------------------------------------------- /.claude/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "permissions": { 3 | "allow": [ 4 | "Bash(mise run build:*)", 5 | "Bash(mise run test:*)" 6 | ], 7 | "deny": [ 8 | "Edit(.golden/**)" 9 | ] 10 | } 11 | } -------------------------------------------------------------------------------- /test/testcases/malgo/TestExplicitModule.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module Prelude = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | def main = { Prelude.putStrLn "Hello, world" } 5 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:recommended", 5 | ":semanticCommitTypeAll(deps)", 6 | ":semanticCommitScopeDisabled" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /test/testcases/malgo/error/QualifiedImport.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../../runtime/malgo/Builtin.mlg" 2 | module P = import "../../../../runtime/malgo/Prelude.mlg" 3 | 4 | def main = { 5 | putStrLn "Hello, world!" 6 | } 7 | -------------------------------------------------------------------------------- /test/testcases/malgo/Echo.mlg: -------------------------------------------------------------------------------- 1 | #c-style-apply 2 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 3 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 4 | 5 | def main = { (_) -> 6 | putStr(getContents({})) 7 | } 8 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/error/MissingImportInForeign/actual: -------------------------------------------------------------------------------- 1 | test/Malgo/ParserSpec/errors/MissingImportInForeign.mlg:1:9: 2 | | 3 | 1 | foreign malgo_newline : () -> () 4 | | ^^^^^^ 5 | unexpected "malgo_" 6 | expecting "import" 7 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/error/MissingImportInForeign/golden: -------------------------------------------------------------------------------- 1 | test/Malgo/ParserSpec/errors/MissingImportInForeign.mlg:1:9: 2 | | 3 | 1 | foreign malgo_newline : () -> () 4 | | ^^^^^^ 5 | unexpected "malgo_" 6 | expecting "import" 7 | -------------------------------------------------------------------------------- /test/testcases/malgo/Double.mlg: -------------------------------------------------------------------------------- 1 | #c-style-apply 2 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 3 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 4 | 5 | def main = { (_) -> 6 | putStr(toStringDouble(3.14)) 7 | } 8 | -------------------------------------------------------------------------------- /test/testcases/malgo/TypeAnnotation.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | def main = { 5 | printString (({x -> x} : String -> String) "hoge") 6 | } 7 | -------------------------------------------------------------------------------- /test/testcases/malgo/Test2.mlg: -------------------------------------------------------------------------------- 1 | data RGB = R | G | B 2 | 3 | def rtob = {R -> B, a -> a} 4 | 5 | foreign import malgo_print_string : String# -> () 6 | 7 | def main = { {B -> malgo_print_string "OK"#, _ -> malgo_print_string "WRONG"# } (rtob R) } 8 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/error/MissingParentheses/actual: -------------------------------------------------------------------------------- 1 | test/Malgo/ParserSpec/errors/MissingParentheses.mlg:5:1: 2 | | 3 | 5 | } 4 | | ^^ 5 | unexpected "}" 6 | expecting "let", "with", '"', ''', '(', ')', '[', '_', '{', digit, integer, or letter 7 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/error/MissingParentheses/golden: -------------------------------------------------------------------------------- 1 | test/Malgo/ParserSpec/errors/MissingParentheses.mlg:5:1: 2 | | 3 | 5 | } 4 | | ^^ 5 | unexpected "}" 6 | expecting "let", "with", '"', ''', '(', ')', '[', '_', '{', digit, integer, or letter 7 | -------------------------------------------------------------------------------- /test/testcases/malgo/Test1.mlg: -------------------------------------------------------------------------------- 1 | data Bool = True | False 2 | 3 | def if = {True t _ -> t (), False _ f -> f ()} 4 | 5 | foreign import malgo_print_string : String# -> () 6 | 7 | def main = {if True {malgo_print_string "True"#} {malgo_print_string "False"#}} 8 | -------------------------------------------------------------------------------- /test/testcases/malgo/Pattern.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | def isNil = { 5 | [] -> True, 6 | _ -> False, 7 | } 8 | 9 | def main = { putStrLn "OK" } 10 | -------------------------------------------------------------------------------- /test/testcases/malgo/TestList.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | def main = { 5 | let xs = [1, 2, 3]; 6 | let nil = []; 7 | putStrLn (toStringInt32 (head xs)) 8 | } 9 | -------------------------------------------------------------------------------- /test/testcases/malgo/SameImport.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 3 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 4 | 5 | def main = { 6 | putStr (getContents ()) 7 | } 8 | -------------------------------------------------------------------------------- /test/testcases/malgo/TestDot.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | def succ = {(Int64# x) -> (Int64# (addInt64# x 1i64#))} 5 | 6 | def main = { printInt64 ((succ << succ) (Int64# 0i64#)) } 7 | -------------------------------------------------------------------------------- /examples/malgo/Cast.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../runtime/malgo/Prelude.mlg" 3 | 4 | def main = { 5 | let x = 1; 6 | let x_ = malgo_unsafe_cast x; 7 | let x__ = malgo_unsafe_cast x; 8 | x__ |> toStringInt32 |> putStrLn 9 | } -------------------------------------------------------------------------------- /test/testcases/malgo/HelloImport.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | def main : {()} 5 | def main = { 6 | putStr (String# "hello"#); 7 | putStrLn |> { f -> f (String# " world"#) } 8 | } 9 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/Echo/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Echo.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (def 6 | main 7 | (fn ((clause (_) (seq (do (apply putStr (apply getContents (tuple))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/Echo/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Echo.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (def 6 | main 7 | (fn ((clause (_) (seq (do (apply putStr (apply getContents (tuple))))))))))) -------------------------------------------------------------------------------- /test/testcases/malgo/DeferLaw.mlg: -------------------------------------------------------------------------------- 1 | #c-style-apply 2 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 3 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 4 | 5 | def f : a -> a 6 | def f = { (x) -> { (_) -> x }({}) } 7 | 8 | def main = { (_) -> 9 | putStrLn(f("Hello")) 10 | } 11 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/CStyleTypeSynonym/actual: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($CStyleTypeSynonym.param_7) 5 | (select 6 | $CStyleTypeSynonym.param_7 7 | ((#CStyleTypeSynonym.__6 (apply (invoke Int32#) (42_i32)))))))) 8 | ("runtime/malgo/Builtin.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/CStyleTypeSynonym/golden: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($CStyleTypeSynonym.param_7) 5 | (select 6 | $CStyleTypeSynonym.param_7 7 | ((#CStyleTypeSynonym.__6 (apply (invoke Int32#) (42_i32)))))))) 8 | ("runtime/malgo/Builtin.mlg")) -------------------------------------------------------------------------------- /examples/malgo/String.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../runtime/malgo/Prelude.mlg" 3 | 4 | def main = { 5 | let str1 = "Hello"; 6 | let str2 = "world"; 7 | printChar <| atString 0i64 str1; 8 | putStrLn <| appendString str1 <| appendString " " str2 9 | } 10 | -------------------------------------------------------------------------------- /test/testcases/malgo/Ones.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | def ones = { 5 | #.head -> 1, 6 | #.tail -> ones 7 | } 8 | 9 | def main = { (_) -> 10 | printString(toStringInt32(ones.tail.tail.tail.tail.tail.head)) 11 | } -------------------------------------------------------------------------------- /test/testcases/malgo/error/InvalidPattern.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../../runtime/malgo/Prelude.mlg" 3 | 4 | def isNil = { 5 | [] -> True, 6 | _ _ -> False, 7 | -- ^ different number of patterns 8 | } 9 | 10 | def main = { putStrLn "OK" } 11 | -------------------------------------------------------------------------------- /hie.yaml: -------------------------------------------------------------------------------- 1 | cradle: 2 | cabal: 3 | - path: "src" 4 | component: "lib:malgo" 5 | 6 | - path: "app/malgo/Main.hs" 7 | component: "malgo:exe:malgo" 8 | 9 | - path: "app/malgo/Paths_malgo.hs" 10 | component: "malgo:exe:malgo" 11 | 12 | - path: "test" 13 | component: "malgo:test:malgo-test" -------------------------------------------------------------------------------- /test/testcases/malgo/Test6.mlg: -------------------------------------------------------------------------------- 1 | data RGB = R | G | B 2 | 3 | foreign import malgo_exit_failure : () -> a 4 | 5 | def rtob = {R -> B, _ -> malgo_exit_failure () } 6 | 7 | foreign import malgo_print_string : String# -> () 8 | 9 | def main = { {B -> malgo_print_string "OK"#, _ -> malgo_print_string "WRONG"# } (rtob R) } 10 | -------------------------------------------------------------------------------- /test/testcases/malgo/Test0.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | 3 | infixl 0 (|>) 4 | def (|>) : a -> (a -> b) -> b 5 | def (|>) = { x f -> f x } 6 | 7 | infixl 6 (+#) 8 | def (+#) = {x y -> addInt64# x y} 9 | 10 | def main = { Int64# 1i64# |> {(Int64# i) -> printString# (toStringInt64# i)} } 11 | -------------------------------------------------------------------------------- /test/testcases/malgo/ForallType.mlg.disabled: -------------------------------------------------------------------------------- 1 | module { String# } = import "../../../runtime/malgo/Builtin.mlg" 2 | module { putStrLn } = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | def identity : forall a. a -> a 5 | def identity = { a -> a } 6 | 7 | def main : {()} 8 | def main = { 9 | putStrLn (identity (String# "hello"#)) 10 | } 11 | -------------------------------------------------------------------------------- /test/testcases/malgo/error/StringPatIsNotSupported.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../../runtime/malgo/Prelude.mlg" 3 | 4 | def isHoge = { 5 | "hoge" -> True, 6 | _ -> False 7 | } 8 | 9 | def main = { 10 | if (isHoge "hoge") { putStrLn "OK" } { putStrLn "Err" } 11 | } 12 | -------------------------------------------------------------------------------- /test/testcases/malgo/FuncOverUnboxed.mlg: -------------------------------------------------------------------------------- 1 | module { toStringInt64#, printString# } = import "../../../runtime/malgo/Builtin.mlg" 2 | 3 | def f = 4 | { 0i64# -> printString# (toStringInt64# 1i64#), 5 | 1i64# -> printString# (toStringInt64# 1i64#), 6 | _ -> printString# (toStringInt64# 0i64#), 7 | } 8 | 9 | def main = { 10 | f 0i64# 11 | } 12 | -------------------------------------------------------------------------------- /examples/malgo/Record.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../runtime/malgo/Prelude.mlg" 3 | 4 | type Person = { name: String, age: Int32 } 5 | 6 | def personAge = { { name = _, age = age } -> age } 7 | 8 | def main = { 9 | personAge {name = "Hoge", age = 42} 10 | |> toStringInt32 11 | |> putStrLn 12 | } -------------------------------------------------------------------------------- /test/testcases/malgo/DataDef.mlg: -------------------------------------------------------------------------------- 1 | #c-style-apply 2 | data Int() = Int#(Int64#) 3 | data List(a) = Nil() | Cons(a, List(a)) 4 | 5 | foreign import malgo_int64_t_to_string : Int64# -> String# 6 | foreign import malgo_print_string : String# -> () 7 | 8 | def main = { (_) -> 9 | { (Int#(x)) -> malgo_print_string(malgo_int64_t_to_string(x)) }(Int#(1i64#)) 10 | } 11 | -------------------------------------------------------------------------------- /test/testcases/malgo/ZeroArgs.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | def one : Int32 5 | def one = { 1 } () 6 | 7 | def id : a -> a 8 | def id = { x -> { x } () } 9 | 10 | def main : { () } 11 | def main = { 12 | { printString (toStringInt32 (id one) ) } 13 | } () 14 | -------------------------------------------------------------------------------- /test/testcases/malgo/TuplePattern.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | data T = A | B | C 5 | 6 | def main : { () } 7 | def main = { 8 | (A, B) 9 | |> { (A, rest) -> printString "A", 10 | (B, rest) -> (), 11 | (C, rest) -> () 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/testcases/malgo/error/NeedSpaceDot.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../../runtime/malgo/Prelude.mlg" 3 | 4 | def succ = { x -> addInt32 x 1 } 5 | 6 | def main = { 7 | Prelude.putStrLn "Hello, world!"; 8 | Prelude.printInt32 <| (succ.succ) 1 9 | -- ^^^^^^^^^ 10 | } 11 | 12 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/CStyleTypeSynonym/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/CStyleTypeSynonym.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (type IntWrapper () Int32) 5 | (type Optional (a) a) 6 | (type Function (a b) (-> a b)) 7 | (type Callback (a b c) (-> a (-> b c))) 8 | (def main (fn ((clause (_) (seq (do (int32 42))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/CStyleTypeSynonym/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/CStyleTypeSynonym.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (type IntWrapper () Int32) 5 | (type Optional (a) a) 6 | (type Function (a b) (-> a b)) 7 | (type Callback (a b c) (-> a (-> b c))) 8 | (def main (fn ((clause (_) (seq (do (int32 42))))))))) -------------------------------------------------------------------------------- /test/testcases/malgo/Undefined.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | def f : Int32 -> Int32 5 | def f = undefined 6 | 7 | def g : Int32 -> Int32 8 | def g = { x -> undefined } 9 | 10 | def main = { 11 | let x = undefined; 12 | let y = g x; 13 | printString "OK" 14 | } 15 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/Double/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Double.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (def 6 | main 7 | (fn 8 | ((clause 9 | (_) 10 | (seq (do (apply putStr (apply toStringDouble (double 3.14_f64))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/Double/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Double.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (def 6 | main 7 | (fn 8 | ((clause 9 | (_) 10 | (seq (do (apply putStr (apply toStringDouble (double 3.14_f64))))))))))) -------------------------------------------------------------------------------- /test/testcases/malgo/Seq.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | def executeWhenLoaded = ( 5 | let x = 1; 6 | let y = 2; 7 | printString (toStringInt32 (addInt32 x y)); 8 | addInt32 x y 9 | ) 10 | 11 | def main = { 12 | printString (toStringInt32 executeWhenLoaded) 13 | } 14 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/Pattern/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Pattern.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (def 6 | isNil 7 | (fn ((clause ((list)) (seq (do True))) (clause (_) (seq (do False)))))) 8 | (def main (fn ((clause (_) (seq (do (apply putStrLn (string "OK")))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/Pattern/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Pattern.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (def 6 | isNil 7 | (fn ((clause ((list)) (seq (do True))) (clause (_) (seq (do False)))))) 8 | (def main (fn ((clause (_) (seq (do (apply putStrLn (string "OK")))))))))) -------------------------------------------------------------------------------- /test/testcases/malgo/UseModule.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module Prelude = import "../../../runtime/malgo/Prelude.mlg" 3 | module {addInt32, (<|), (<<)} = import "../../../runtime/malgo/Prelude.mlg" 4 | 5 | def succ = { x -> addInt32 x 1 } 6 | 7 | def main = { 8 | Prelude.putStrLn "Hello, world!"; 9 | Prelude.printInt32 <| (succ << succ) 1 10 | } 11 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/CStyleDataDef/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/CStyleDataDef.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (data List (a) ((Cons (a (app List (a)))) (Nil ()))) 5 | (data Map (k v) ((Entry (k v)) (Empty ()))) 6 | (data Tree (a) ((Node (a (app Tree (a)) (app Tree (a)))) (Leaf ()))) 7 | (def main (fn ((clause (_) (seq (do (int32 42))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/CStyleDataDef/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/CStyleDataDef.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (data List (a) ((Cons (a (app List (a)))) (Nil ()))) 5 | (data Map (k v) ((Entry (k v)) (Empty ()))) 6 | (data Tree (a) ((Node (a (app Tree (a)) (app Tree (a)))) (Leaf ()))) 7 | (def main (fn ((clause (_) (seq (do (int32 42))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/Echo/actual: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($Echo.param_1) 5 | (select 6 | $Echo.param_1 7 | ((#Echo.__0 8 | (apply 9 | (invoke putStr) 10 | ((apply (invoke getContents) ((tuple ()))))))))))) 11 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/Echo/golden: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($Echo.param_1) 5 | (select 6 | $Echo.param_1 7 | ((#Echo.__0 8 | (apply 9 | (invoke putStr) 10 | ((apply (invoke getContents) ((tuple ()))))))))))) 11 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /test/testcases/malgo/Bool.mlg: -------------------------------------------------------------------------------- 1 | #c-style-apply 2 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 3 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 4 | 5 | def ifChain = { 6 | #(False).then(_).else(e) -> e({}), 7 | #(True).then(t).else(_) -> t({}), 8 | } 9 | 10 | def main = { (_) -> 11 | ifChain(True).then({ (_) -> putStrLn("True") }).else({ (_) -> putStrLn("False") }) 12 | } -------------------------------------------------------------------------------- /test/testcases/malgo/RecordFieldAccess.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | data B = B { a: Int32, b: Int32 } 5 | 6 | def f = { { a = a, b = _ } -> a } 7 | 8 | def g = { B { a = a, b = _ } -> a } 9 | 10 | def main = { 11 | let x = { a = 32, b = 10 }; 12 | printString (toStringInt32 (addInt32 (f x) x.b)) 13 | } 14 | -------------------------------------------------------------------------------- /test/testcases/malgo/Test3.mlg: -------------------------------------------------------------------------------- 1 | data Tag = A | B 2 | data List a = Nil | Cons a (List a) 3 | 4 | infixl 0 (|>) 5 | def (|>) : a -> (a -> b) -> b 6 | def (|>) = {x f -> f x} 7 | 8 | foreign import malgo_print_string : String# -> () 9 | 10 | def main = { 11 | Cons A (Cons B Nil) |> { 12 | (Cons A (Cons B Nil)) -> malgo_print_string "OK"#, 13 | _ -> malgo_print_string "WRONG"# 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/testcases/malgo/TestLet.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | 3 | infixl 0 (|>) 4 | def (|>) : a -> (a -> b) -> b 5 | def (|>) = {x f -> f x} 6 | 7 | def main = { 8 | let x = addInt32# 1# 2#; 9 | printString# (toStringInt32# x); 10 | 11 | let x = Int32# (addInt32# 1# 2#); 12 | let printInt32 = {(Int32# x) -> printString# (toStringInt32# x)}; 13 | printInt32 x 14 | } 15 | -------------------------------------------------------------------------------- /test/testcases/malgo/EvenOdd.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | def even = { 5 | 0 -> True, 6 | n -> odd (subInt32 n 1), 7 | } 8 | 9 | def odd = { 10 | 0 -> False, 11 | n -> even (subInt32 n 1), 12 | } 13 | 14 | def main = 15 | { { False -> putStrLn "False", 16 | True -> putStrLn "True" } (even 10) } 17 | -------------------------------------------------------------------------------- /test/Malgo/RenameSpec/errors/NotQualifiedImported.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../../runtime/malgo/Builtin.mlg" 2 | -- module Prelude = import "../../../../runtime/malgo/Prelude.mlg" 3 | module {addInt32, (<|), (<<)} = import "../../../../runtime/malgo/Prelude.mlg" 4 | 5 | def succ = { x -> addInt32 x 1 } 6 | 7 | def main = { 8 | Prelude.putStrLn "Hello, world!"; 9 | Prelude.printInt32 <| (succ << succ) 1 10 | } 11 | -------------------------------------------------------------------------------- /test/testcases/malgo/EmptyConstructor.mlg: -------------------------------------------------------------------------------- 1 | #c-style-apply 2 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 3 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 4 | 5 | -- Constructor that takes no arguments 6 | data Empty = Empty 7 | 8 | -- Constructor that takes unit 9 | data Unit = Unit({}) 10 | 11 | def main = { () -> 12 | let x = Empty; 13 | let y = Unit(); 14 | print(x); 15 | print(y) 16 | } -------------------------------------------------------------------------------- /.golden/Malgo.Parser/SameImport/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/SameImport.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Builtin.mlg" all) 5 | (import "runtime/malgo/Prelude.mlg" all) 6 | (def 7 | main 8 | (fn 9 | ((clause 10 | (_) 11 | (seq (do (apply putStr (parens (apply getContents (tuple)))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/SameImport/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/SameImport.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Builtin.mlg" all) 5 | (import "runtime/malgo/Prelude.mlg" all) 6 | (def 7 | main 8 | (fn 9 | ((clause 10 | (_) 11 | (seq (do (apply putStr (parens (apply getContents (tuple)))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/Echo/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Echo.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#Echo.__0) 8 | (seq (do (apply putStr (apply getContents (tuple))))))))))) 9 | () 10 | () 11 | () 12 | () 13 | ((import "runtime/malgo/Builtin.mlg" all) 14 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/Echo/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Echo.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#Echo.__0) 8 | (seq (do (apply putStr (apply getContents (tuple))))))))))) 9 | () 10 | () 11 | () 12 | () 13 | ((import "runtime/malgo/Builtin.mlg" all) 14 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | labels: 8 | - dependencies 9 | - github-actions 10 | open-pull-requests-limit: 10 11 | - package-ecosystem: "docker" 12 | directory: "/" 13 | schedule: 14 | interval: "weekly" 15 | labels: 16 | - dependencies 17 | - docker 18 | -------------------------------------------------------------------------------- /test/testcases/malgo/Pragma.mlg: -------------------------------------------------------------------------------- 1 | foreign import malgo_print_string : String# -> () 2 | foreign import malgo_newline : () -> () 3 | 4 | data String = String# String# 5 | 6 | def putStrLn : String -> () 7 | def putStrLn = { (String# str) -> 8 | malgo_print_string str; 9 | malgo_newline () 10 | } 11 | 12 | def string# : String# -> String 13 | def string# = { x -> String# x } 14 | 15 | def main = { 16 | putStrLn "Hello, world" 17 | } 18 | -------------------------------------------------------------------------------- /wiki/2025-09-06-empty-arguments.md: -------------------------------------------------------------------------------- 1 | # empty-arguments 2 | 3 | Created: 2025-09-06 4 | 5 | 引き続き空の引数について考える。 6 | 7 | `f()` は `f({})` の省略である、と考えるのが自然かもしれない。 8 | 9 | ```malgo 10 | def f = { () -> 1 } 11 | f() === f({}) === 1 12 | ``` 13 | 14 | 型についても考える。0引数のコンストラクタは、`{}`を引数にとることになる。 15 | このようなコンストラクタに意味はない。よって、0引数のコンストラクタは定義できないことにする。 16 | 代わりに、`Nil`のように、引数を取らないコンストラクタを用意する。 17 | 18 | ```malgo 19 | data List(a) = Nil | Cons(a, List(a)) 20 | ``` -------------------------------------------------------------------------------- /test/testcases/malgo/HelloBoxed.mlg: -------------------------------------------------------------------------------- 1 | foreign import malgo_print_string : String# -> () 2 | foreign import malgo_newline : () -> () 3 | 4 | data String = String# String# 5 | 6 | def putStrLn : String -> () 7 | def putStrLn = { (String# str) -> 8 | malgo_print_string str; 9 | malgo_newline () 10 | } 11 | 12 | def string# : String# -> String 13 | def string# = { x -> String# x } 14 | 15 | def main = { 16 | putStrLn "Hello, world" 17 | } 18 | -------------------------------------------------------------------------------- /test/testcases/malgo/TestPolySynonym.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | type Fun0 a = {a} 5 | 6 | type Pair a b = { fst: b, snd: a } 7 | 8 | def first : { fst: a, snd: b } -> a 9 | def first = { { fst = x, snd = _ } -> x } 10 | 11 | def main : Fun0 () 12 | def main = { 13 | let x = { fst = 1, snd = "hoge" }; 14 | first x |> printInt32 15 | } 16 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/TestExplicitModule/actual: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($TestExplicitModule.param_1) 5 | (select 6 | $TestExplicitModule.param_1 7 | ((#TestExplicitModule.__0 8 | (apply 9 | (invoke putStrLn) 10 | ((apply (invoke String#) ("Hello, world")))))))))) 11 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/TestExplicitModule/golden: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($TestExplicitModule.param_1) 5 | (select 6 | $TestExplicitModule.param_1 7 | ((#TestExplicitModule.__0 8 | (apply 9 | (invoke putStrLn) 10 | ((apply (invoke String#) ("Hello, world")))))))))) 11 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /test/Malgo/RenameSpec/errors/UndefinedType.mlg: -------------------------------------------------------------------------------- 1 | foreign import malgo_print_string : String# -> () 2 | foreign import malgo_newline : () -> () 3 | 4 | -- data String = String# String# 5 | 6 | def putStrLn : String -> () 7 | def putStrLn = { (String# str) -> 8 | malgo_print_string str; 9 | malgo_newline () 10 | } 11 | 12 | def string# : String# -> String 13 | def string# = { x -> String# x } 14 | 15 | def main = { 16 | putStrLn "Hello, world" 17 | } 18 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/TestExplicitModule/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/TestExplicitModule.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" (as Prelude)) 5 | (def 6 | main 7 | (fn 8 | ((clause 9 | (_) 10 | (seq 11 | (do 12 | (apply (project Prelude "putStrLn") (string "Hello, world")))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/TestExplicitModule/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/TestExplicitModule.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" (as Prelude)) 5 | (def 6 | main 7 | (fn 8 | ((clause 9 | (_) 10 | (seq 11 | (do 12 | (apply (project Prelude "putStrLn") (string "Hello, world")))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/SameImport/actual: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($SameImport.param_1) 5 | (select 6 | $SameImport.param_1 7 | ((#SameImport.__0 8 | (apply 9 | (invoke putStr) 10 | ((apply (invoke getContents) ((tuple ()))))))))))) 11 | ("runtime/malgo/Builtin.mlg" 12 | "runtime/malgo/Builtin.mlg" 13 | "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/SameImport/golden: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($SameImport.param_1) 5 | (select 6 | $SameImport.param_1 7 | ((#SameImport.__0 8 | (apply 9 | (invoke putStr) 10 | ((apply (invoke getContents) ((tuple ()))))))))))) 11 | ("runtime/malgo/Builtin.mlg" 12 | "runtime/malgo/Builtin.mlg" 13 | "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /test/testcases/malgo/CStyleDataDef.mlg: -------------------------------------------------------------------------------- 1 | #c-style-apply 2 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 3 | 4 | -- C-style data definition with parenthesized parameters 5 | data List(a) = Cons(a, List(a)) | Nil() 6 | 7 | -- C-style data definition with multiple parameters 8 | data Map(k, v) = Entry(k, v) | Empty() 9 | 10 | -- C-style data definition with simple constructor 11 | data Tree(a) = Node(a, Tree(a), Tree(a)) | Leaf() 12 | 13 | def main = { (_) -> 42 } 14 | -------------------------------------------------------------------------------- /test/testcases/malgo/RecordTest.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | type A = { a: Int32, b: Int32 } 5 | 6 | data B = B A 7 | 8 | type C a = { x: a, y: a } 9 | 10 | def f = { { a = a, b = _ } -> a } 11 | 12 | def g = { (B { a = a, b = _ }) -> a } 13 | 14 | def main = { 15 | let x = { a = 32, b = 10 }; 16 | printString (toStringInt32 (addInt32 (f x) ({{a=_,b=b} -> b} x))) 17 | } 18 | -------------------------------------------------------------------------------- /test/testcases/malgo/TestPatSynRecon.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | infixl 6 (+#) 5 | def (+#) = {x y -> addInt64# x y} 6 | 7 | def sum = 8 | { (Cons (Int64# x) xs) -> 9 | sum xs |> {(Int64# s) -> Int64# (x +# s)}, 10 | Nil -> Int64# 0i64# 11 | } 12 | 13 | def main = { 14 | sum (Cons (Int64# 1i64#) (Cons (Int64# 2i64#) Nil)) 15 | |> {i -> printInt64 i} 16 | } 17 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/Double/actual: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($Double.param_1) 5 | (select 6 | $Double.param_1 7 | ((#Double.__0 8 | (apply 9 | (invoke putStr) 10 | ((apply 11 | (invoke toStringDouble) 12 | ((apply (invoke Double#) (3.14_f64)))))))))))) 13 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/Double/golden: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($Double.param_1) 5 | (select 6 | $Double.param_1 7 | ((#Double.__0 8 | (apply 9 | (invoke putStr) 10 | ((apply 11 | (invoke toStringDouble) 12 | ((apply (invoke Double#) (3.14_f64)))))))))))) 13 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /examples/malgo/Fib.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../runtime/malgo/Prelude.mlg" 3 | 4 | infix 4 (<=) 5 | def (<=) = { x y -> leInt32 x y } 6 | 7 | infixl 6 (+) 8 | def (+) = { x y -> addInt32 x y } 9 | 10 | infixl 6 (-) 11 | def (-) = { x y -> subInt32 x y } 12 | 13 | def fib = { n -> 14 | if (n <= 1) 15 | { 1 } 16 | { fib (n - 1) + fib (n - 2) } 17 | } 18 | 19 | def main = { 20 | fib 5 |> toStringInt32 |> putStrLn 21 | } -------------------------------------------------------------------------------- /test/Malgo/ParserSpec/errors/InvalidIdentifier.mlg: -------------------------------------------------------------------------------- 1 | foreign import malgo_print_string : String# -> () 2 | foreign import malgo_newline : () -> () 3 | 4 | data String = String# String# 5 | 6 | -- `let` does not allowed as identifier 7 | def let : String -> () 8 | def let = { (String# str) -> 9 | malgo_print_string str; 10 | malgo_newline () 11 | } 12 | 13 | def string# : String# -> String 14 | def string# = { x -> String# x } 15 | 16 | def main = { 17 | let "Hello, world" 18 | } 19 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToCore/CStyleTypeSynonym/actual: -------------------------------------------------------------------------------- 1 | ((main 2 | $CStyleTypeSynonym.return_8 3 | (cut 4 | (lambda 5 | ($CStyleTypeSynonym.param_7 $CStyleTypeSynonym.return_9) 6 | (cut 7 | $CStyleTypeSynonym.param_7 8 | (select 9 | (#CStyleTypeSynonym.__6 10 | (invoke Int32# (apply (42_i32) ($CStyleTypeSynonym.return_9))))))) 11 | $CStyleTypeSynonym.return_8)) 12 | ("runtime/malgo/Builtin.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToCore/CStyleTypeSynonym/golden: -------------------------------------------------------------------------------- 1 | ((main 2 | $CStyleTypeSynonym.return_8 3 | (cut 4 | (lambda 5 | ($CStyleTypeSynonym.param_7 $CStyleTypeSynonym.return_9) 6 | (cut 7 | $CStyleTypeSynonym.param_7 8 | (select 9 | (#CStyleTypeSynonym.__6 10 | (invoke Int32# (apply (42_i32) ($CStyleTypeSynonym.return_9))))))) 11 | $CStyleTypeSynonym.return_8)) 12 | ("runtime/malgo/Builtin.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/Primitive/actual: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($Primitive.param_1) 5 | (select 6 | $Primitive.param_1 7 | ((#Primitive.__0 8 | (apply 9 | (invoke printString#) 10 | ((apply 11 | (invoke toStringInt64#) 12 | ((apply (apply (invoke addInt64#) (40_i64)) (2_i64)))))))))))) 13 | ("runtime/malgo/Builtin.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/Primitive/golden: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($Primitive.param_1) 5 | (select 6 | $Primitive.param_1 7 | ((#Primitive.__0 8 | (apply 9 | (invoke printString#) 10 | ((apply 11 | (invoke toStringInt64#) 12 | ((apply (apply (invoke addInt64#) (40_i64)) (2_i64)))))))))))) 13 | ("runtime/malgo/Builtin.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToCore/CStyleTypeSynonym/flat/actual: -------------------------------------------------------------------------------- 1 | ((main 2 | $CStyleTypeSynonym.return_8 3 | (cut 4 | (lambda 5 | ($CStyleTypeSynonym.param_7 $CStyleTypeSynonym.return_9) 6 | (cut 7 | $CStyleTypeSynonym.param_7 8 | (select 9 | (#CStyleTypeSynonym.__6 10 | (invoke Int32# (apply (42_i32) ($CStyleTypeSynonym.return_9))))))) 11 | $CStyleTypeSynonym.return_8)) 12 | ("runtime/malgo/Builtin.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToCore/CStyleTypeSynonym/flat/golden: -------------------------------------------------------------------------------- 1 | ((main 2 | $CStyleTypeSynonym.return_8 3 | (cut 4 | (lambda 5 | ($CStyleTypeSynonym.param_7 $CStyleTypeSynonym.return_9) 6 | (cut 7 | $CStyleTypeSynonym.param_7 8 | (select 9 | (#CStyleTypeSynonym.__6 10 | (invoke Int32# (apply (42_i32) ($CStyleTypeSynonym.return_9))))))) 11 | $CStyleTypeSynonym.return_8)) 12 | ("runtime/malgo/Builtin.mlg")) -------------------------------------------------------------------------------- /cabal.project: -------------------------------------------------------------------------------- 1 | packages: *.cabal 2 | 3 | jobs: $ncpus 4 | 5 | tests: True 6 | 7 | semaphore: true 8 | 9 | package * 10 | ghc-options: 11 | +RTS -A128m -n2m -RTS 12 | 13 | package malgo 14 | -- '-j' option and RTS options are from: Keeping Compilation Fast https://www.parsonsmatt.org/2019/11/27/keeping_compilation_fast.html 15 | ghc-options: 16 | -fno-ignore-asserts 17 | -j +RTS -A128m -n2m -RTS 18 | 19 | constraints: diagnose +megaparsec-compat 20 | 21 | allow-newer: text 22 | -------------------------------------------------------------------------------- /test/testcases/malgo/error/ConstructorArity.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../../runtime/malgo/Prelude.mlg" 3 | 4 | type A = { a: Int32, b: Int32 } 5 | 6 | data B = B A 7 | 8 | type C a = { x: a, y: a } 9 | 10 | def f = { { a = a, b = _ } -> a } 11 | 12 | def g = { (B { a = a, b = _ }) -> a } 13 | 14 | def main = { 15 | let x = { a = 32, b = 10 }; 16 | printString (toStringInt32 (addInt32 (f x) ({{a=_,b=b} -> b} x))) 17 | } 18 | -------------------------------------------------------------------------------- /.golden/Malgo.Rename/SameImport/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/SameImport.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#SameImport.__0) 8 | (seq (do (apply putStr (parens (apply getContents (tuple)))))))))))) 9 | () 10 | () 11 | () 12 | () 13 | ((import "runtime/malgo/Builtin.mlg" all) 14 | (import "runtime/malgo/Builtin.mlg" all) 15 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/SameImport/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/SameImport.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#SameImport.__0) 8 | (seq (do (apply putStr (parens (apply getContents (tuple)))))))))))) 9 | () 10 | () 11 | () 12 | () 13 | ((import "runtime/malgo/Builtin.mlg" all) 14 | (import "runtime/malgo/Builtin.mlg" all) 15 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /test/testcases/malgo/TypeSynonym.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | type MyTuple a = (a, a) 5 | 6 | type MyString = String 7 | 8 | def hello : MyTuple MyString 9 | def hello = ("hello", "world") 10 | 11 | data T = TCon 12 | type S = T 13 | 14 | def idOverS : S -> T 15 | def idOverS = { x -> x } 16 | 17 | def main : { () } 18 | def main = { 19 | hello |> { (h, w) -> putStr h; putStr " "; putStrLn w } 20 | } 21 | -------------------------------------------------------------------------------- /.golden/Malgo.Rename/TestExplicitModule/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/TestExplicitModule.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#TestExplicitModule.__0) 8 | (seq 9 | (do (apply putStrLn (apply String# (string "Hello, world"))))))))))) 10 | () 11 | () 12 | () 13 | () 14 | ((import "runtime/malgo/Builtin.mlg" all) 15 | (import "runtime/malgo/Prelude.mlg" (as Prelude))))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/TestExplicitModule/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/TestExplicitModule.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#TestExplicitModule.__0) 8 | (seq 9 | (do (apply putStrLn (apply String# (string "Hello, world"))))))))))) 10 | () 11 | () 12 | () 13 | () 14 | ((import "runtime/malgo/Builtin.mlg" all) 15 | (import "runtime/malgo/Prelude.mlg" (as Prelude))))) -------------------------------------------------------------------------------- /test/testcases/malgo/CStyleTypeSynonym.mlg: -------------------------------------------------------------------------------- 1 | #c-style-apply 2 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 3 | 4 | -- C-style type synonym with empty parameter list 5 | type IntWrapper() = Int32 6 | 7 | -- C-style type synonym with single parameter 8 | type Optional(a) = a 9 | 10 | -- C-style type synonym with multiple parameters 11 | type Function(a, b) = a -> b 12 | 13 | -- C-style type synonym with complex type expression 14 | type Callback(a, b, c) = a -> b -> c 15 | 16 | def main = { (_) -> 42 } 17 | -------------------------------------------------------------------------------- /examples/malgo/Tarai.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../runtime/malgo/Prelude.mlg" 3 | 4 | infix 4 (<=) 5 | def (<=) = { (Int64# x) (Int64# y) -> isTrue# (leInt64# x y) } 6 | 7 | infixl 6 (-) 8 | def (-) = { x y -> subInt64 x y } 9 | 10 | def tarai = { x y z -> 11 | if (x <= y) 12 | { y } 13 | { tarai (tarai (x - 1i64) y z) (tarai (y - 1i64) z x) (tarai (z - 1i64) x y) } 14 | } 15 | 16 | def main = { 17 | putStrLn (toStringInt64 (tarai 6i64 2i64 0i64)) 18 | } -------------------------------------------------------------------------------- /test/testcases/malgo/ToplevelVariable.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | def one = 1 5 | 6 | def addOne = addInt32 one 7 | 8 | def constId = const identity 9 | 10 | def comp : Maybe a 11 | def comp = 12 | { Nothing -> Nothing, 13 | (Just x) -> Nothing 14 | } (Just ()) 15 | 16 | def main = { 17 | { Nothing -> printString "OK", 18 | (Just _) -> () 19 | } comp; 20 | printInt32 (constId const (addOne one)) 21 | } 22 | -------------------------------------------------------------------------------- /test/Malgo/RenameSpec/errors/UndefinedTypeVariable.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../../runtime/malgo/Prelude.mlg" 3 | 4 | type MyTuple = (a, a) 5 | 6 | type MyString = String 7 | 8 | def hello : MyTuple MyString 9 | def hello = ("hello", "world") 10 | 11 | data T = TCon 12 | type S = T 13 | 14 | def idOverS : S -> T 15 | def idOverS = { x -> x } 16 | 17 | def main : { () } 18 | def main = { 19 | hello |> { (h, w) -> putStr h; putStr " "; putStrLn w } 20 | } 21 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/DeferLaw/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/DeferLaw.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (sig f (-> a a)) 6 | (def 7 | f 8 | (fn 9 | ((clause 10 | (x) 11 | (seq (do (apply (fn ((clause (_) (seq (do x))))) (tuple)))))))) 12 | (def 13 | main 14 | (fn 15 | ((clause (_) (seq (do (apply putStrLn (apply f (string "Hello"))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/DeferLaw/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/DeferLaw.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (sig f (-> a a)) 6 | (def 7 | f 8 | (fn 9 | ((clause 10 | (x) 11 | (seq (do (apply (fn ((clause (_) (seq (do x))))) (tuple)))))))) 12 | (def 13 | main 14 | (fn 15 | ((clause (_) (seq (do (apply putStrLn (apply f (string "Hello"))))))))))) -------------------------------------------------------------------------------- /test/testcases/malgo/Fib.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | type Stream a = { head: a, tail: Stream a } 5 | 6 | def zipWith = { f xs ys -> 7 | { head = f xs.head ys.head, 8 | tail = zipWith f xs.tail ys.tail 9 | } 10 | } 11 | 12 | def fib = { 13 | head = 1i64, 14 | tail = { head = 1i64, tail = zipWith addInt64 fib fib.tail } 15 | } 16 | 17 | def main = { 18 | printString (toStringInt64 (fib.tail.tail.tail.tail.tail.head)) 19 | } -------------------------------------------------------------------------------- /.pinact.yaml: -------------------------------------------------------------------------------- 1 | # yaml-language-server: $schema=https://raw.githubusercontent.com/suzuki-shunsuke/pinact/refs/heads/main/json-schema/pinact.json 2 | # pinact - https://github.com/suzuki-shunsuke/pinact 3 | version: 3 4 | # files: 5 | # - pattern: action.yaml 6 | # - pattern: */action.yaml 7 | 8 | ignore_actions: 9 | # - name: slsa-framework/slsa-github-generator/\.github/workflows/generator_generic_slsa3\.yml 10 | # ref: v\d+\.\d+\.\d+ 11 | # - name: actions/.* 12 | # ref: main 13 | # - name: suzuki-shunsuke/.* 14 | # ref: release-.* 15 | -------------------------------------------------------------------------------- /examples/malgo/Infixing.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../runtime/malgo/Prelude.mlg" 3 | 4 | infixl 3 (<\) 5 | def (<\) = {x f -> {y -> f x y}} 6 | 7 | infixl 3 (\>) 8 | def (\>) = {f y -> f y} 9 | 10 | infixr 3 ( f x} 12 | 13 | infixr 3 (/>) 14 | def (/>) = {f y -> {x -> f x y}} 15 | 16 | def printInt = { x -> x |> toStringInt64 |> printString } 17 | 18 | def main = { 19 | printInt (1i64 <\addInt64\> 2i64); 20 | printInt (1i64 2i64) 21 | } 22 | -------------------------------------------------------------------------------- /test/testcases/malgo/EmptyArguments.mlg: -------------------------------------------------------------------------------- 1 | #c-style-apply 2 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 3 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 4 | 5 | -- Function that takes no arguments. 6 | -- It actually takes a unit argument internally. 7 | def empty = { () -> 0 } 8 | 9 | -- Function that takes unit. 10 | def unit = { ({}) -> 1 } 11 | 12 | def main = { () -> 13 | let x = empty(); -- This is actually empty({}) 14 | let y = unit(); -- This is actually unit({}) 15 | printInt32(x); 16 | printInt32(y); 17 | } -------------------------------------------------------------------------------- /test/testcases/malgo/Factorial.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | infix 4 (==) 5 | def (==) = { x y -> eqInt64 x y } 6 | 7 | infixl 6 (-) 8 | def (-) = { x y -> subInt64 x y } 9 | 10 | infixl 7 (*) 11 | def (*) = { x y -> mulInt64 x y } 12 | 13 | def fact = { n -> factAcc n 1i64 } 14 | 15 | def factAcc = { n acc -> if (n == 0i64) { acc } { factAcc (n - 1i64) (n * acc) } } 16 | 17 | def main = { 18 | fact 5i64 |> toStringInt64 |> putStrLn 19 | } 20 | -------------------------------------------------------------------------------- /test/testcases/malgo/error/NonExhaustive.mlg: -------------------------------------------------------------------------------- 1 | infixl 0 (|>) 2 | def (|>) : a -> (a -> b) -> b 3 | def (|>) = {x f -> f x} 4 | 5 | data String = String# String# 6 | 7 | foreign import malgo_print_string : String# -> () 8 | 9 | def string# : String# -> String 10 | def string# = { x -> String# x } 11 | 12 | data List a = Nil | Cons a (List a) 13 | 14 | def head : List a -> a 15 | def head = { (Cons x Nil) -> x } 16 | 17 | def main = { 18 | let xs = [String# "a"#, String# "b"#]; 19 | (head xs) |> { String# x -> malgo_print_string x } 20 | } 21 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/Pattern/actual: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($Pattern.param_2) 5 | (select 6 | $Pattern.param_2 7 | ((#Pattern.__1 8 | (apply (invoke putStrLn) ((apply (invoke String#) ("OK"))))))))) 9 | (isNil 10 | (lambda 11 | ($Pattern.param_3) 12 | (select 13 | $Pattern.param_3 14 | (((Nil ()) (invoke True)) (#Pattern.__0 (invoke False))))))) 15 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/Pattern/golden: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($Pattern.param_2) 5 | (select 6 | $Pattern.param_2 7 | ((#Pattern.__1 8 | (apply (invoke putStrLn) ((apply (invoke String#) ("OK"))))))))) 9 | (isNil 10 | (lambda 11 | ($Pattern.param_3) 12 | (select 13 | $Pattern.param_3 14 | (((Nil ()) (invoke True)) (#Pattern.__0 (invoke False))))))) 15 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/Double/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Double.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#Double.__0) 8 | (seq 9 | (do 10 | (apply 11 | putStr 12 | (apply toStringDouble (apply Double# (double 3.14_f64)))))))))))) 13 | () 14 | () 15 | () 16 | () 17 | ((import "runtime/malgo/Builtin.mlg" all) 18 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/Double/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Double.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#Double.__0) 8 | (seq 9 | (do 10 | (apply 11 | putStr 12 | (apply toStringDouble (apply Double# (double 3.14_f64)))))))))))) 13 | () 14 | () 15 | () 16 | () 17 | ((import "runtime/malgo/Builtin.mlg" all) 18 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /test/testcases/malgo/InlineFunction.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | infix 4 (<=) 5 | def (<=) = { x y -> leInt32 x y } 6 | 7 | infixl 6 (+) 8 | def (+) = { x y -> addInt32 x y } 9 | 10 | infixl 6 (-) 11 | def (-) = { x y -> subInt32 x y } 12 | 13 | def fix = { f x -> f (fix f) x } 14 | 15 | def main = { 16 | let fib = fix { f n -> 17 | if (n <= 1) 18 | { 1 } 19 | { f (n - 1) + f (n - 2) } 20 | }; 21 | fib 5 |> toStringInt32 |> putStrLn 22 | } 23 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/EmptyConstructor/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/EmptyConstructor.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (data Empty () ((Empty ()))) 6 | (data Unit () ((Unit ((tuple))))) 7 | (def 8 | main 9 | (fn 10 | ((clause 11 | (_) 12 | (seq 13 | (let x Empty) 14 | (let y (apply Unit (tuple))) 15 | (do (apply print x)) 16 | (do (apply print y))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/EmptyConstructor/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/EmptyConstructor.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (data Empty () ((Empty ()))) 6 | (data Unit () ((Unit ((tuple))))) 7 | (def 8 | main 9 | (fn 10 | ((clause 11 | (_) 12 | (seq 13 | (let x Empty) 14 | (let y (apply Unit (tuple))) 15 | (do (apply print x)) 16 | (do (apply print y))))))))) -------------------------------------------------------------------------------- /test/testcases/malgo/FibCopattern.mlg: -------------------------------------------------------------------------------- 1 | #c-style-apply 2 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 3 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 4 | 5 | type Stream(a) = { head: a, tail: Stream(a) } 6 | 7 | def zipWith = { 8 | #(f, xs, ys).head -> f(xs.head, ys.head), 9 | #(f, xs, ys).tail -> zipWith(f, xs.tail, ys.tail) 10 | } 11 | 12 | def fib = { 13 | #.head -> 1i64, 14 | #.tail.head -> 1i64, 15 | #.tail.tail -> zipWith(addInt64, fib, fib.tail) 16 | } 17 | 18 | def main = { (_) -> 19 | printString(toStringInt64(fib.tail.tail.tail.tail.tail.head)) 20 | } -------------------------------------------------------------------------------- /test/testcases/malgo/With.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | def finally : (a -> r) -> {a} -> r 5 | def finally = { finalizer k -> 6 | let x = k (); 7 | finalizer x 8 | } 9 | 10 | def twice : {a} -> a 11 | def twice = { k -> 12 | k (); 13 | k () 14 | } 15 | 16 | def printAndReturn = { str k -> 17 | printString str; 18 | k str 19 | } 20 | 21 | def main = { 22 | with finally { () -> printString "end" }; 23 | with twice; 24 | with x = printAndReturn "foo"; 25 | printString x 26 | } 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .#* 3 | 4 | .DS_Store 5 | .dir-locals.el 6 | 7 | .stack-work/ 8 | dist-newstyle/ 9 | .ghc.* 10 | stack.yaml.lock 11 | cabal.project.local 12 | 13 | .vim/ 14 | 15 | a.out 16 | tmp/ 17 | test/tmp/ 18 | 19 | *.ll 20 | *.mlgi 21 | *.idx 22 | *.kor 23 | *.mo 24 | 25 | !.golden/**/*.ll 26 | 27 | .shake/ 28 | .malgo-work/ 29 | 30 | *.prof 31 | 32 | .hie/ 33 | weeder.dhall 34 | 35 | *.satysfi-aux 36 | 37 | compile_flags.txt 38 | 39 | sisku_config.json 40 | 41 | target/ 42 | 43 | result* 44 | 45 | node_modules/ 46 | 47 | .direnv/ 48 | 49 | .envrc 50 | 51 | .claude/settings.local.json -------------------------------------------------------------------------------- /test/testcases/malgo/error/InferEither.mlg: -------------------------------------------------------------------------------- 1 | -- Issue: Compiler crashes when defining data Either a b = Left a | Right b 2 | -- https://github.com/malgo-lang/malgo/issues/59 3 | 4 | module {..} = import Builtin 5 | module {..} = import Prelude 6 | 7 | data Either a b = Left a | Right b 8 | 9 | def id1 : Either String Int32 -> Either String Int32 10 | def id1 = {x -> x} 11 | 12 | def id2 : Either Bool Int32 -> Either Bool Int32 13 | def id2 = {x -> x} 14 | 15 | def main = { 16 | let x = Right 1; 17 | -- type error (String is not Bool) 18 | id1 x |> id2 |> { Right y -> printInt32 y } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/TestList/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/TestList.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (def 6 | main 7 | (fn 8 | ((clause 9 | (_) 10 | (seq 11 | (let xs (list (int32 1) (int32 2) (int32 3))) 12 | (let nil (list)) 13 | (do 14 | (apply 15 | putStrLn 16 | (parens (apply toStringInt32 (parens (apply head xs))))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/TestList/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/TestList.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (def 6 | main 7 | (fn 8 | ((clause 9 | (_) 10 | (seq 11 | (let xs (list (int32 1) (int32 2) (int32 3))) 12 | (let nil (list)) 13 | (do 14 | (apply 15 | putStrLn 16 | (parens (apply toStringInt32 (parens (apply head xs))))))))))))) -------------------------------------------------------------------------------- /test/testcases/malgo/CStyleApply.mlg: -------------------------------------------------------------------------------- 1 | #c-style-apply 2 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 3 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 4 | 5 | infix 4 (==) 6 | def (==) = { (x, y) -> eqInt64(x, y) } 7 | 8 | infixl 6 (-) 9 | def (-) = { (x, y) -> subInt64(x, y) } 10 | 11 | infixl 7 (*) 12 | def (*) = { (x, y) -> mulInt64(x, y) } 13 | 14 | def fact = { (n) -> factAcc({n, 1i64}) } 15 | 16 | def factAcc = { ({n, acc}) -> if(n == 0i64, { (_) -> acc }, { (_) -> factAcc({n - 1i64, n * acc}) }) } 17 | 18 | def main = { (_) -> 19 | fact(5i64) |> toStringInt64 |> putStrLn 20 | } -------------------------------------------------------------------------------- /.golden/Malgo.Parser/Undefined/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Undefined.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (sig f (-> Int32 Int32)) 6 | (def f undefined) 7 | (sig g (-> Int32 Int32)) 8 | (def g (fn ((clause (x) (seq (do undefined)))))) 9 | (def 10 | main 11 | (fn 12 | ((clause 13 | (_) 14 | (seq 15 | (let x undefined) 16 | (let y (apply g x)) 17 | (do (apply printString (string "OK")))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/Undefined/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Undefined.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (sig f (-> Int32 Int32)) 6 | (def f undefined) 7 | (sig g (-> Int32 Int32)) 8 | (def g (fn ((clause (x) (seq (do undefined)))))) 9 | (def 10 | main 11 | (fn 12 | ((clause 13 | (_) 14 | (seq 15 | (let x undefined) 16 | (let y (apply g x)) 17 | (do (apply printString (string "OK")))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/Pattern/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Pattern.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#Pattern.__1) 8 | (seq (do (apply putStrLn (apply String# (string "OK")))))))))) 9 | ((def 10 | isNil 11 | (fn 12 | ((clause ((con Nil ())) (seq (do True))) 13 | (clause (#Pattern.__0) (seq (do False)))))))) 14 | () 15 | () 16 | () 17 | () 18 | ((import "runtime/malgo/Builtin.mlg" all) 19 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/Pattern/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Pattern.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#Pattern.__1) 8 | (seq (do (apply putStrLn (apply String# (string "OK")))))))))) 9 | ((def 10 | isNil 11 | (fn 12 | ((clause ((con Nil ())) (seq (do True))) 13 | (clause (#Pattern.__0) (seq (do False)))))))) 14 | () 15 | () 16 | () 17 | () 18 | ((import "runtime/malgo/Builtin.mlg" all) 19 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/Primitive/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Primitive.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (def 5 | main 6 | (fn 7 | ((clause 8 | (_) 9 | (seq 10 | (do 11 | (apply 12 | printString# 13 | (parens 14 | (apply 15 | toStringInt64# 16 | (parens 17 | (apply (apply addInt64# (int64 40)) (int64 2)))))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/Primitive/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Primitive.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (def 5 | main 6 | (fn 7 | ((clause 8 | (_) 9 | (seq 10 | (do 11 | (apply 12 | printString# 13 | (parens 14 | (apply 15 | toStringInt64# 16 | (parens 17 | (apply (apply addInt64# (int64 40)) (int64 2)))))))))))))) -------------------------------------------------------------------------------- /test/testcases/malgo/error/ErrorPatSynRecon.mlg: -------------------------------------------------------------------------------- 1 | data Int = Int# Int64# 2 | 3 | foreign import malgo_add_i64 : Int64# -> Int64# -> Int64# 4 | 5 | infixl 6 (+#) 6 | def (+#) = {x y -> malgo_add_i64 x y} 7 | 8 | infixl 0 (|>) 9 | def (|>) : a -> (a -> b) -> b 10 | def (|>) = {x f -> f x} 11 | 12 | data List a = Nil | Cons a (List a) 13 | 14 | def sum = 15 | { Cons Int# x xs -> -- Error: invalid pattern 16 | sum xs |> {(Int# s) -> Int# (x +# s)}, 17 | Nil -> Int# 0i64# 18 | } 19 | 20 | foreign import print_int : Int64# -> () 21 | 22 | def main = { 23 | let x = sum (Cons (Int# 1i64#) (Cons (Int# 2i64#) Nil)); 24 | () 25 | } 26 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/EmptyArguments/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/EmptyArguments.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (def empty (fn ((clause (_) (seq (do (int32 0))))))) 6 | (def unit (fn ((clause ((tuple)) (seq (do (int32 1))))))) 7 | (def 8 | main 9 | (fn 10 | ((clause 11 | (_) 12 | (seq 13 | (let x (apply empty (tuple))) 14 | (let y (apply unit (tuple))) 15 | (do (apply printInt32 x)) 16 | (do (apply printInt32 y))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/EmptyArguments/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/EmptyArguments.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (def empty (fn ((clause (_) (seq (do (int32 0))))))) 6 | (def unit (fn ((clause ((tuple)) (seq (do (int32 1))))))) 7 | (def 8 | main 9 | (fn 10 | ((clause 11 | (_) 12 | (seq 13 | (let x (apply empty (tuple))) 14 | (let y (apply unit (tuple))) 15 | (do (apply printInt32 x)) 16 | (do (apply printInt32 y))))))))) -------------------------------------------------------------------------------- /examples/malgo/Either.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../runtime/malgo/Prelude.mlg" 3 | 4 | data Either a b = Left a | Right b 5 | 6 | def id = {x -> x} 7 | 8 | def andThen = { 9 | _ (Left x) -> Left x, 10 | f (Right x) -> f x, 11 | } 12 | 13 | def main = { 14 | let x = Right 1; 15 | 16 | x |> andThen { x -> Right (addInt32 x 1) } 17 | |> andThen { y -> y |> toStringInt32 |> putStr |> Right }; 18 | 19 | x |> andThen { _ -> Left "error" } 20 | |> andThen { x -> Right (addInt32 x 1) } 21 | |> { (Left err) -> putStrLn err, 22 | (Right x) -> x |> toStringInt32 |> putStrLn } 23 | } 24 | -------------------------------------------------------------------------------- /test/testcases/malgo/TestArithDouble.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | -- operators for Double# 5 | def neg = { x -> subDouble# 0.0# x } 6 | 7 | infixl 7 (*) 8 | def (*) = {x y -> mulDouble# x y} 9 | 10 | def mul = {x y -> mulDouble# x y} 11 | 12 | infixl 6 (+) 13 | def (+) = {x y -> addDouble# x y} 14 | 15 | def add = {x y -> addDouble# x y} 16 | 17 | def show = {x -> String# (toStringDouble# x)} 18 | 19 | def traceShowId = { x -> putStrLn (show x); x } 20 | 21 | def f : Double# -> Double# 22 | def f = {x -> (x + 0.0#) * x} 23 | 24 | def main = { 25 | putStrLn (show (f 0.5#)) 26 | } 27 | -------------------------------------------------------------------------------- /.devcontainer/post-create.sh: -------------------------------------------------------------------------------- 1 | /home/vscode/.local/bin/mise trust 2 | /home/vscode/.local/bin/mise install 3 | # /home/vscode/.local/bin/mise run setup 4 | /home/vscode/.local/share/mise/installs/ghcup/0.1.50.2/ghcup install ghc 9.12.2 5 | /home/vscode/.local/share/mise/installs/ghcup/0.1.50.2/ghcup set ghc 9.12.2 6 | /home/vscode/.local/share/mise/installs/ghcup/0.1.50.2/ghcup install cabal latest 7 | /home/vscode/.local/share/mise/installs/ghcup/0.1.50.2/ghcup set cabal latest 8 | cabal update 9 | cabal install hpack --overwrite-policy=always 10 | cabal install ormolu --overwrite-policy=always 11 | # /home/vscode/.local/bin/mise run setup-hls 12 | ghcup compile hls -g 2.11.0.0 --ghc 9.12.2 --cabal-update -------------------------------------------------------------------------------- /.golden/Malgo.Rename/Primitive/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Primitive.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#Primitive.__0) 8 | (seq 9 | (do 10 | (apply 11 | printString# 12 | (parens 13 | (apply 14 | toStringInt64# 15 | (parens 16 | (apply (apply addInt64# (int64 40)) (int64 2)))))))))))))) 17 | () 18 | () 19 | () 20 | () 21 | ((import "runtime/malgo/Builtin.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/Primitive/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Primitive.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#Primitive.__0) 8 | (seq 9 | (do 10 | (apply 11 | printString# 12 | (parens 13 | (apply 14 | toStringInt64# 15 | (parens 16 | (apply (apply addInt64# (int64 40)) (int64 2)))))))))))))) 17 | () 18 | () 19 | () 20 | () 21 | ((import "runtime/malgo/Builtin.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToCore/CStyleTypeSynonym/join/actual: -------------------------------------------------------------------------------- 1 | ((main 2 | $CStyleTypeSynonym.return_8 3 | (cut 4 | (lambda 5 | ($CStyleTypeSynonym.param_7 $CStyleTypeSynonym.return_9) 6 | (join 7 | $CStyleTypeSynonym.select_11 8 | (select 9 | (#CStyleTypeSynonym.__6 10 | (join 11 | $CStyleTypeSynonym.apply_10 12 | (apply (42_i32) ($CStyleTypeSynonym.return_9)) 13 | (invoke Int32# $CStyleTypeSynonym.apply_10)))) 14 | (cut $CStyleTypeSynonym.param_7 $CStyleTypeSynonym.select_11))) 15 | $CStyleTypeSynonym.return_8)) 16 | ("runtime/malgo/Builtin.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToCore/CStyleTypeSynonym/join/golden: -------------------------------------------------------------------------------- 1 | ((main 2 | $CStyleTypeSynonym.return_8 3 | (cut 4 | (lambda 5 | ($CStyleTypeSynonym.param_7 $CStyleTypeSynonym.return_9) 6 | (join 7 | $CStyleTypeSynonym.select_11 8 | (select 9 | (#CStyleTypeSynonym.__6 10 | (join 11 | $CStyleTypeSynonym.apply_10 12 | (apply (42_i32) ($CStyleTypeSynonym.return_9)) 13 | (invoke Int32# $CStyleTypeSynonym.apply_10)))) 14 | (cut $CStyleTypeSynonym.param_7 $CStyleTypeSynonym.select_11))) 15 | $CStyleTypeSynonym.return_8)) 16 | ("runtime/malgo/Builtin.mlg")) -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: feature requests 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.golden/Malgo.Rename/EmptyConstructor/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/EmptyConstructor.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#EmptyConstructor.__0) 8 | (seq 9 | (let #EmptyConstructor.x_1 Empty) 10 | (let #EmptyConstructor.y_2 (apply Unit (tuple))) 11 | (do (apply print #EmptyConstructor.x_1)) 12 | (do (apply print #EmptyConstructor.y_2))))))))) 13 | () 14 | ((data Empty () ((Empty ()))) (data Unit () ((Unit ((tuple)))))) 15 | () 16 | () 17 | ((import "runtime/malgo/Builtin.mlg" all) 18 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/EmptyConstructor/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/EmptyConstructor.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#EmptyConstructor.__0) 8 | (seq 9 | (let #EmptyConstructor.x_1 Empty) 10 | (let #EmptyConstructor.y_2 (apply Unit (tuple))) 11 | (do (apply print #EmptyConstructor.x_1)) 12 | (do (apply print #EmptyConstructor.y_2))))))))) 13 | () 14 | ((data Empty () ((Empty ()))) (data Unit () ((Unit ((tuple)))))) 15 | () 16 | () 17 | ((import "runtime/malgo/Builtin.mlg" all) 18 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/TestPolySynonym/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/TestPolySynonym.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (type Fun0 (a) (block a)) 6 | (type Pair (a b) (record (fst b) (snd a))) 7 | (sig first (-> (record (fst a) (snd b)) a)) 8 | (def first (fn ((clause ((record (fst x) (snd _))) (seq (do x)))))) 9 | (sig main (app Fun0 ((tuple)))) 10 | (def 11 | main 12 | (fn 13 | ((clause 14 | (_) 15 | (seq 16 | (let x (record (fst (int32 1)) (snd (string "hoge")))) 17 | (do (opapp |> (apply first x) printInt32))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/TestPolySynonym/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/TestPolySynonym.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (type Fun0 (a) (block a)) 6 | (type Pair (a b) (record (fst b) (snd a))) 7 | (sig first (-> (record (fst a) (snd b)) a)) 8 | (def first (fn ((clause ((record (fst x) (snd _))) (seq (do x)))))) 9 | (sig main (app Fun0 ((tuple)))) 10 | (def 11 | main 12 | (fn 13 | ((clause 14 | (_) 15 | (seq 16 | (let x (record (fst (int32 1)) (snd (string "hoge")))) 17 | (do (opapp |> (apply first x) printInt32))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/TypeAnnotation/actual: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($TypeAnnotation.param_2) 5 | (select 6 | $TypeAnnotation.param_2 7 | ((#TypeAnnotation.__0 8 | (apply 9 | (invoke printString) 10 | ((apply 11 | (lambda 12 | ($TypeAnnotation.param_3) 13 | (select 14 | $TypeAnnotation.param_3 15 | ((#TypeAnnotation.x_1 #TypeAnnotation.x_1)))) 16 | ((apply (invoke String#) ("hoge")))))))))))) 17 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/TypeAnnotation/golden: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($TypeAnnotation.param_2) 5 | (select 6 | $TypeAnnotation.param_2 7 | ((#TypeAnnotation.__0 8 | (apply 9 | (invoke printString) 10 | ((apply 11 | (lambda 12 | ($TypeAnnotation.param_3) 13 | (select 14 | $TypeAnnotation.param_3 15 | ((#TypeAnnotation.x_1 #TypeAnnotation.x_1)))) 16 | ((apply (invoke String#) ("hoge")))))))))))) 17 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /test/testcases/malgo/Punctuate.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | infixr 6 (<>) 5 | def (<>) : String -> String -> String 6 | def (<>) = appendString 7 | 8 | data SExpr = Symbol String 9 | | SInt Int32 10 | | SList (List SExpr) 11 | 12 | def show : SExpr -> String 13 | def show = 14 | { (Symbol str) -> "Symbol " <> str, 15 | (SInt int) -> "SInt " <> toStringInt32 int, 16 | (SList ss) -> "SList [" <> concatString (punctuate ", " (mapList show ss)) <> "]" 17 | } 18 | 19 | def main = { 20 | -- (x (y (z))) 21 | let x = SList [Symbol "x", SList [Symbol "y", SList [Symbol "z"]]]; 22 | putStrLn (show x) 23 | } 24 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToCore/Echo/actual: -------------------------------------------------------------------------------- 1 | ((main 2 | $Echo.return_2 3 | (cut 4 | (lambda 5 | ($Echo.param_1 $Echo.return_3) 6 | (cut 7 | $Echo.param_1 8 | (select 9 | (#Echo.__0 10 | (invoke 11 | putStr 12 | (apply 13 | ((do 14 | $Echo.return_4 15 | (invoke 16 | getContents 17 | (apply ((construct tuple () ())) ($Echo.return_4))))) 18 | ($Echo.return_3))))))) 19 | $Echo.return_2)) 20 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToCore/Echo/golden: -------------------------------------------------------------------------------- 1 | ((main 2 | $Echo.return_2 3 | (cut 4 | (lambda 5 | ($Echo.param_1 $Echo.return_3) 6 | (cut 7 | $Echo.param_1 8 | (select 9 | (#Echo.__0 10 | (invoke 11 | putStr 12 | (apply 13 | ((do 14 | $Echo.return_4 15 | (invoke 16 | getContents 17 | (apply ((construct tuple () ())) ($Echo.return_4))))) 18 | ($Echo.return_3))))))) 19 | $Echo.return_2)) 20 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/Undefined/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Undefined.mlg" 3 | ((((def g (fn ((clause (#Undefined.x_0) (seq (do undefined))))))) 4 | ((def 5 | main 6 | (fn 7 | ((clause 8 | (#Undefined.__1) 9 | (seq 10 | (let #Undefined.x_2 undefined) 11 | (let #Undefined.y_3 (apply g #Undefined.x_2)) 12 | (do (apply printString (apply String# (string "OK")))))))))) 13 | ((def f undefined))) 14 | ((sig f (-> Int32 Int32)) (sig g (-> Int32 Int32))) 15 | () 16 | () 17 | () 18 | ((import "runtime/malgo/Builtin.mlg" all) 19 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/Undefined/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Undefined.mlg" 3 | ((((def g (fn ((clause (#Undefined.x_0) (seq (do undefined))))))) 4 | ((def 5 | main 6 | (fn 7 | ((clause 8 | (#Undefined.__1) 9 | (seq 10 | (let #Undefined.x_2 undefined) 11 | (let #Undefined.y_3 (apply g #Undefined.x_2)) 12 | (do (apply printString (apply String# (string "OK")))))))))) 13 | ((def f undefined))) 14 | ((sig f (-> Int32 Int32)) (sig g (-> Int32 Int32))) 15 | () 16 | () 17 | () 18 | ((import "runtime/malgo/Builtin.mlg" all) 19 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /test/testcases/malgo/FieldPrefix.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | type Point2D = { x : Int32, y : Int32 } 5 | 6 | type Point3D = { x : Float, y : Float, z : Float } 7 | 8 | def print2D = { { x = x, y = y } -> 9 | printString (toStringInt32 x); 10 | printString ", "; 11 | printString (toStringInt32 y) 12 | } 13 | 14 | def x2D : Point2D -> Int32 15 | def x2D = { { x = x, y = _ } -> x } 16 | 17 | def y2D : Point2D -> Int32 18 | def y2D = { { x = _, y = y } -> y } 19 | 20 | def zero2D : Point2D 21 | def zero2D = { x = 0, y = 0 } 22 | 23 | def zero3D : Point3D 24 | def zero3D = { x = 0.0f32, y = 0.0f32, z = 0.0f32 } 25 | 26 | def main = { 27 | print2D zero2D 28 | } 29 | -------------------------------------------------------------------------------- /test/testcases/malgo/TestEither.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | data Either a b = Left a | Right b 5 | 6 | def id = {x -> x} 7 | 8 | def andThen = 9 | { _ (Left x) -> Left x, 10 | f (Right x) -> f x } 11 | 12 | def main = { 13 | Right 1 |> { (Right x) -> putStr (toStringInt32 x), _ -> putStrLn "unreachable" }; 14 | 15 | let x = Right 1; 16 | 17 | x |> andThen { x -> Right (addInt32 x 1) } 18 | |> andThen { y -> y |> toStringInt32 |> putStr |> Right }; 19 | 20 | x |> andThen { _ -> Left "error" } 21 | |> andThen { x -> Right (addInt32 x 1) } 22 | |> { (Left err) -> putStrLn err, 23 | (Right x) -> x |> toStringInt32 |> putStrLn } 24 | } 25 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/TypeAnnotation/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/TypeAnnotation.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (def 6 | main 7 | (fn 8 | ((clause 9 | (_) 10 | (seq 11 | (do 12 | (apply 13 | printString 14 | (parens 15 | (apply 16 | (parens 17 | (ann 18 | (fn ((clause (x) (seq (do x))))) 19 | (-> String String))) 20 | (string "hoge")))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/TypeAnnotation/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/TypeAnnotation.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (def 6 | main 7 | (fn 8 | ((clause 9 | (_) 10 | (seq 11 | (do 12 | (apply 13 | printString 14 | (parens 15 | (apply 16 | (parens 17 | (ann 18 | (fn ((clause (x) (seq (do x))))) 19 | (-> String String))) 20 | (string "hoge")))))))))))) -------------------------------------------------------------------------------- /examples/malgo/LazyList.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../runtime/malgo/Prelude.mlg" 3 | 4 | data LazyList a = LNil | LCons a {LazyList a} 5 | 6 | def nil : {LazyList a} 7 | def nil = {LNil} 8 | 9 | def cons : a -> {LazyList a} -> {LazyList a} 10 | def cons = { x xs -> {LCons x xs} } 11 | 12 | def map = { f xs -> { 13 | xs () |> 14 | { LNil -> LNil, 15 | (LCons x xs) -> LCons (f x) (map f xs) 16 | } 17 | } 18 | } 19 | 20 | def sum = { xs -> 21 | xs () |> { LNil -> 0i64, 22 | (LCons x xs) -> addInt64 x (sum xs) 23 | } 24 | } 25 | 26 | def main = { 27 | let xs = {LCons 1i64 {LCons 2i64 nil}}; 28 | sum (cons 1i64 (cons 2i64 nil)) 29 | |> toStringInt64 30 | |> putStrLn 31 | } 32 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/Pragma/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Pragma.mlg" 3 | ((foreign malgo_print_string (-> String# (tuple))) 4 | (foreign malgo_newline (-> (tuple) (tuple))) 5 | (data String () ((String# (String#)))) 6 | (sig putStrLn (-> String (tuple))) 7 | (def 8 | putStrLn 9 | (fn 10 | ((clause 11 | ((con String# (str))) 12 | (seq 13 | (do (apply malgo_print_string str)) 14 | (do (apply malgo_newline (tuple)))))))) 15 | (sig string# (-> String# String)) 16 | (def string# (fn ((clause (x) (seq (do (apply String# x))))))) 17 | (def 18 | main 19 | (fn ((clause (_) (seq (do (apply putStrLn (string "Hello, world")))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/Pragma/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Pragma.mlg" 3 | ((foreign malgo_print_string (-> String# (tuple))) 4 | (foreign malgo_newline (-> (tuple) (tuple))) 5 | (data String () ((String# (String#)))) 6 | (sig putStrLn (-> String (tuple))) 7 | (def 8 | putStrLn 9 | (fn 10 | ((clause 11 | ((con String# (str))) 12 | (seq 13 | (do (apply malgo_print_string str)) 14 | (do (apply malgo_newline (tuple)))))))) 15 | (sig string# (-> String# String)) 16 | (def string# (fn ((clause (x) (seq (do (apply String# x))))))) 17 | (def 18 | main 19 | (fn ((clause (_) (seq (do (apply putStrLn (string "Hello, world")))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/HelloBoxed/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/HelloBoxed.mlg" 3 | ((foreign malgo_print_string (-> String# (tuple))) 4 | (foreign malgo_newline (-> (tuple) (tuple))) 5 | (data String () ((String# (String#)))) 6 | (sig putStrLn (-> String (tuple))) 7 | (def 8 | putStrLn 9 | (fn 10 | ((clause 11 | ((con String# (str))) 12 | (seq 13 | (do (apply malgo_print_string str)) 14 | (do (apply malgo_newline (tuple)))))))) 15 | (sig string# (-> String# String)) 16 | (def string# (fn ((clause (x) (seq (do (apply String# x))))))) 17 | (def 18 | main 19 | (fn ((clause (_) (seq (do (apply putStrLn (string "Hello, world")))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/HelloBoxed/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/HelloBoxed.mlg" 3 | ((foreign malgo_print_string (-> String# (tuple))) 4 | (foreign malgo_newline (-> (tuple) (tuple))) 5 | (data String () ((String# (String#)))) 6 | (sig putStrLn (-> String (tuple))) 7 | (def 8 | putStrLn 9 | (fn 10 | ((clause 11 | ((con String# (str))) 12 | (seq 13 | (do (apply malgo_print_string str)) 14 | (do (apply malgo_newline (tuple)))))))) 15 | (sig string# (-> String# String)) 16 | (def string# (fn ((clause (x) (seq (do (apply String# x))))))) 17 | (def 18 | main 19 | (fn ((clause (_) (seq (do (apply putStrLn (string "Hello, world")))))))))) -------------------------------------------------------------------------------- /src/Malgo/Monad.hs: -------------------------------------------------------------------------------- 1 | module Malgo.Monad (Flag (..), runMalgoM) where 2 | 3 | import Effectful (Eff, IOE, runEff) 4 | import Effectful.Reader.Static (Reader, runReader) 5 | import Effectful.State.Static.Local 6 | import Malgo.Features 7 | import Malgo.Interface (Interface) 8 | import Malgo.Module 9 | import Malgo.Prelude 10 | 11 | runMalgoM :: 12 | Flag -> 13 | Eff 14 | '[ Reader Flag, 15 | State Uniq, 16 | State (Map ModuleName Interface), 17 | Features, 18 | State Pragma, 19 | Workspace, 20 | IOE 21 | ] 22 | b -> 23 | IO b 24 | runMalgoM flag e = runEff $ runWorkspaceOnPwd do 25 | runReader flag e 26 | & evalState (Uniq 0) 27 | & evalState @(Map ModuleName Interface) mempty 28 | & runFeatures mempty 29 | & evalState @Pragma mempty 30 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/TestNestedLetFunc/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/TestNestedLetFunc.mlg" 3 | ((foreign malgo_print_string (-> String# (tuple))) 4 | (def 5 | main 6 | (fn 7 | ((clause 8 | (_) 9 | (seq 10 | (let 11 | f 12 | (fn 13 | ((clause 14 | (_) 15 | (seq 16 | (let 17 | y 18 | (apply 19 | (fn ((clause (a) (seq (do (tuple)))))) 20 | (tuple)))))))) 21 | (do (apply malgo_print_string (string "PASS")))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/TestNestedLetFunc/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/TestNestedLetFunc.mlg" 3 | ((foreign malgo_print_string (-> String# (tuple))) 4 | (def 5 | main 6 | (fn 7 | ((clause 8 | (_) 9 | (seq 10 | (let 11 | f 12 | (fn 13 | ((clause 14 | (_) 15 | (seq 16 | (let 17 | y 18 | (apply 19 | (fn ((clause (a) (seq (do (tuple)))))) 20 | (tuple)))))))) 21 | (do (apply malgo_print_string (string "PASS")))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/DeferLaw/actual: -------------------------------------------------------------------------------- 1 | (program 2 | ((f 3 | (lambda 4 | ($DeferLaw.param_4) 5 | (select 6 | $DeferLaw.param_4 7 | ((#DeferLaw.x_1 8 | (apply 9 | (lambda 10 | ($DeferLaw.param_5) 11 | (select $DeferLaw.param_5 ((#DeferLaw.__2 #DeferLaw.x_1)))) 12 | ((tuple ())))))))) 13 | (main 14 | (lambda 15 | ($DeferLaw.param_6) 16 | (select 17 | $DeferLaw.param_6 18 | ((#DeferLaw.__3 19 | (apply 20 | (invoke putStrLn) 21 | ((apply (invoke f) ((apply (invoke String#) ("Hello")))))))))))) 22 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/DeferLaw/golden: -------------------------------------------------------------------------------- 1 | (program 2 | ((f 3 | (lambda 4 | ($DeferLaw.param_4) 5 | (select 6 | $DeferLaw.param_4 7 | ((#DeferLaw.x_1 8 | (apply 9 | (lambda 10 | ($DeferLaw.param_5) 11 | (select $DeferLaw.param_5 ((#DeferLaw.__2 #DeferLaw.x_1)))) 12 | ((tuple ())))))))) 13 | (main 14 | (lambda 15 | ($DeferLaw.param_6) 16 | (select 17 | $DeferLaw.param_6 18 | ((#DeferLaw.__3 19 | (apply 20 | (invoke putStrLn) 21 | ((apply (invoke f) ((apply (invoke String#) ("Hello")))))))))))) 22 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /test/testcases/malgo/Null.mlg: -------------------------------------------------------------------------------- 1 | data Maybe a = Nothing | Just a 2 | 3 | data Bool = False | True 4 | 5 | data List a = Nil | Cons a (List a) 6 | 7 | def isNothing : Maybe a -> Bool 8 | def isNothing = 9 | { Nothing -> True, 10 | (Just _) -> False 11 | } 12 | 13 | def mHead : List a -> Maybe a 14 | def mHead = 15 | { Nil -> Nothing, 16 | (Cons p _) -> Just p 17 | } 18 | 19 | def null : List a -> Bool 20 | def null = { 21 | as -> isNothing (mHead as) 22 | } 23 | 24 | infixl 0 (|>) 25 | def (|>) : a -> (a -> b) -> b 26 | def (|>) = { 27 | x f -> f x 28 | } 29 | 30 | 31 | foreign import malgo_print_string : String# -> () 32 | 33 | foreign import malgo_exit_failure : () -> a 34 | 35 | def main = { 36 | (null (Cons True (Cons True Nil))) 37 | |> { False -> malgo_print_string "OK"#, 38 | True -> malgo_exit_failure () 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/Seq/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Seq.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (def 6 | executeWhenLoaded 7 | (seq 8 | (let x (int32 1)) 9 | (let y (int32 2)) 10 | (do 11 | (apply 12 | printString 13 | (parens 14 | (apply toStringInt32 (parens (apply (apply addInt32 x) y)))))) 15 | (do (apply (apply addInt32 x) y)))) 16 | (def 17 | main 18 | (fn 19 | ((clause 20 | (_) 21 | (seq 22 | (do 23 | (apply 24 | printString 25 | (parens (apply toStringInt32 executeWhenLoaded))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/Seq/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Seq.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (def 6 | executeWhenLoaded 7 | (seq 8 | (let x (int32 1)) 9 | (let y (int32 2)) 10 | (do 11 | (apply 12 | printString 13 | (parens 14 | (apply toStringInt32 (parens (apply (apply addInt32 x) y)))))) 15 | (do (apply (apply addInt32 x) y)))) 16 | (def 17 | main 18 | (fn 19 | ((clause 20 | (_) 21 | (seq 22 | (do 23 | (apply 24 | printString 25 | (parens (apply toStringInt32 executeWhenLoaded))))))))))) -------------------------------------------------------------------------------- /test/testcases/malgo/ShowSimple.mlg: -------------------------------------------------------------------------------- 1 | foreign import malgo_print_string : String# -> () 2 | foreign import malgo_newline : () -> () 3 | 4 | data Int32 = Int32# Int32# 5 | def int32# : Int32# -> Int32 6 | def int32# = { x -> Int32# x } 7 | 8 | data String = String# String# 9 | def string# : String# -> String 10 | def string# = { x -> String# x } 11 | 12 | def putStr : String -> () 13 | def putStr = { (String# x) -> malgo_print_string x } 14 | 15 | foreign import malgo_int32_t_to_string : Int32# -> String# 16 | 17 | type Show a = { 18 | show : a -> String, 19 | } 20 | 21 | def show : Show a -> a -> String 22 | def show = { { show = show } -> show } 23 | 24 | def wrap : (Int32 -> String) -> Show Int32 25 | def wrap = { 26 | fn -> { 27 | show = fn 28 | } 29 | } 30 | 31 | def main = { putStr (show (wrap { (Int32# x) -> String# (malgo_int32_t_to_string x) }) 1) } 32 | -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/Undefined/actual: -------------------------------------------------------------------------------- 1 | (program 2 | ((g 3 | (lambda 4 | ($Undefined.param_4) 5 | (select $Undefined.param_4 ((#Undefined.x_0 (invoke undefined)))))) 6 | (main 7 | (lambda 8 | ($Undefined.param_5) 9 | (select 10 | $Undefined.param_5 11 | ((#Undefined.__1 12 | (let 13 | #Undefined.x_2 14 | (invoke undefined) 15 | (let 16 | #Undefined.y_3 17 | (apply (invoke g) (#Undefined.x_2)) 18 | (apply 19 | (invoke printString) 20 | ((apply (invoke String#) ("OK"))))))))))) 21 | (f (invoke undefined))) 22 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/Undefined/golden: -------------------------------------------------------------------------------- 1 | (program 2 | ((g 3 | (lambda 4 | ($Undefined.param_4) 5 | (select $Undefined.param_4 ((#Undefined.x_0 (invoke undefined)))))) 6 | (main 7 | (lambda 8 | ($Undefined.param_5) 9 | (select 10 | $Undefined.param_5 11 | ((#Undefined.__1 12 | (let 13 | #Undefined.x_2 14 | (invoke undefined) 15 | (let 16 | #Undefined.y_3 17 | (apply (invoke g) (#Undefined.x_2)) 18 | (apply 19 | (invoke printString) 20 | ((apply (invoke String#) ("OK"))))))))))) 21 | (f (invoke undefined))) 22 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[BUG]" 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Create `ReproductionCode.mlg` as below: 16 | ``` 17 | module ReproductionCode = { 18 | .... 19 | } 20 | ``` 21 | 2. `$ malgo to-ll ReproductionCode.mlg` 22 | 3. See error as below: 23 | ``` 24 | malgo: ... 25 | ``` 26 | 27 | **Expected behavior** 28 | A clear and concise description of what you expected to happen. 29 | 30 | **Environment (please complete the following information):** 31 | - OS: [e.g. macOS Big Sur 11.4] 32 | - Shell: [e.g. zsh 5.8 (x86_64-apple-darwin20.1.0)] 33 | 34 | **Additional context** 35 | Add any other context about the problem here. 36 | -------------------------------------------------------------------------------- /.github/disabled-workflows/update-flake-lock.yml: -------------------------------------------------------------------------------- 1 | name: update-flake-lock 2 | on: 3 | workflow_dispatch: # allows manual triggering 4 | schedule: 5 | - cron: '0 0 * * 0' # runs weekly on Sunday at 00:00 6 | 7 | jobs: 8 | lockfile: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout repository 12 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 13 | - name: Install Nix 14 | uses: DeterminateSystems/nix-installer-action@21a544727d0c62386e78b4befe52d19ad12692e3 # v17 15 | - name: Update flake.lock 16 | uses: DeterminateSystems/update-flake-lock@428c2b58a4b7414dabd372acb6a03dba1084d3ab # v25 17 | with: 18 | pr-title: "Update flake.lock" # Title of PR to be created 19 | pr-labels: | # Labels to be set on the PR 20 | dependencies 21 | automated 22 | -------------------------------------------------------------------------------- /.github/workflows/upload-sbom.yml: -------------------------------------------------------------------------------- 1 | name: SBOM upload 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: ["main", "master"] 7 | 8 | jobs: 9 | SBOM-upload: 10 | 11 | runs-on: ubuntu-latest 12 | permissions: 13 | id-token: write 14 | contents: write 15 | 16 | steps: 17 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 18 | - name: Generate SBOM 19 | run: | 20 | curl -sSfL https://get.anchore.io/syft | sudo sh -s -- -b $RUNNER_TEMP 21 | $RUNNER_TEMP/syft scan dir:./ -o spdx-json=sbom.spdx.json 22 | - uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 23 | with: 24 | name: sbom 25 | path: sbom.spdx.json 26 | - name: SBOM upload 27 | uses: advanced-security/spdx-dependency-submission-action@5530bab9ee4bbe66420ce8280624036c77f89746 # v0.1.1 28 | -------------------------------------------------------------------------------- /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/devcontainers/base:debian 2 | 3 | RUN apt-get update && apt-get install -y build-essential curl libffi-dev libffi8ubuntu1 libncurses-dev libncurses6 libtinfo6 libgc-dev lsb-release wget gnupg pkg-config ripgrep retry && rm -rf /var/lib/apt/lists/* 4 | 5 | RUN rm -rf /var/lib/apt/lists/* 6 | 7 | USER vscode 8 | 9 | # install haskell 10 | 11 | # ENV BOOTSTRAP_HASKELL_NONINTERACTIVE=1 12 | # 13 | # ENV BOOTSTRAP_HASKELL_GHC_VERSION=9.12.2 14 | # ENV BOOTSTRAP_HASKELL_CABAL_VERSION=3.12.1.0 15 | # # Disable HLS installation 16 | # # ENV BOOTSTRAP_HASKELL_INSTALL_HLS=0 17 | # ENV BOOTSTRAP_HASKELL_HLS_VERSION=2.11.0.0 18 | # 19 | # RUN curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh 20 | 21 | # install mise 22 | RUN curl https://mise.run | sh 23 | 24 | RUN echo 'eval "$(/home/vscode/.local/bin/mise activate bash)"' >> /home/vscode/.bashrc -------------------------------------------------------------------------------- /.golden/Malgo.Parser/TuplePattern/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/TuplePattern.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (data T () ((A ()) (B ()) (C ()))) 6 | (sig main (block (tuple))) 7 | (def 8 | main 9 | (fn 10 | ((clause 11 | (_) 12 | (seq 13 | (do 14 | (opapp 15 | |> 16 | (tuple A B) 17 | (fn 18 | ((clause 19 | ((tuple A rest)) 20 | (seq (do (apply printString (string "A"))))) 21 | (clause ((tuple B rest)) (seq (do (tuple)))) 22 | (clause ((tuple C rest)) (seq (do (tuple))))))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/TuplePattern/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/TuplePattern.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (data T () ((A ()) (B ()) (C ()))) 6 | (sig main (block (tuple))) 7 | (def 8 | main 9 | (fn 10 | ((clause 11 | (_) 12 | (seq 13 | (do 14 | (opapp 15 | |> 16 | (tuple A B) 17 | (fn 18 | ((clause 19 | ((tuple A rest)) 20 | (seq (do (apply printString (string "A"))))) 21 | (clause ((tuple B rest)) (seq (do (tuple)))) 22 | (clause ((tuple C rest)) (seq (do (tuple))))))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/UseModule/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/UseModule.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" (as Prelude)) 5 | (import "runtime/malgo/Prelude.mlg" (selected addInt32 <| <<)) 6 | (def 7 | succ 8 | (fn ((clause (x) (seq (do (apply (apply addInt32 x) (int32 1)))))))) 9 | (def 10 | main 11 | (fn 12 | ((clause 13 | (_) 14 | (seq 15 | (do 16 | (apply 17 | (project Prelude "putStrLn") 18 | (string "Hello, world!"))) 19 | (do 20 | (opapp 21 | <| 22 | (project Prelude "printInt32") 23 | (apply (parens (opapp << succ succ)) (int32 1))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/UseModule/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/UseModule.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" (as Prelude)) 5 | (import "runtime/malgo/Prelude.mlg" (selected addInt32 <| <<)) 6 | (def 7 | succ 8 | (fn ((clause (x) (seq (do (apply (apply addInt32 x) (int32 1)))))))) 9 | (def 10 | main 11 | (fn 12 | ((clause 13 | (_) 14 | (seq 15 | (do 16 | (apply 17 | (project Prelude "putStrLn") 18 | (string "Hello, world!"))) 19 | (do 20 | (opapp 21 | <| 22 | (project Prelude "printInt32") 23 | (apply (parens (opapp << succ succ)) (int32 1))))))))))) -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | // For format details, see https://aka.ms/devcontainer.json. For config options, see the 2 | // README at: https://github.com/devcontainers/templates/tree/main/src/debian 3 | { 4 | "name": "DevContainer", 5 | // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile 6 | "build": { 7 | "dockerfile": "Dockerfile" 8 | }, 9 | "remoteEnv": { 10 | "PATH": "${containerEnv:PATH}:/home/vscode/.ghcup/bin:/home/vscode/.cabal/bin:/home/vscode/.go/bin:/home/vscode/.local/share/mise/installs/ghcup/latest" 11 | }, 12 | "customizations": { 13 | "vscode": { 14 | "extensions": [ 15 | "haskell.haskell", 16 | "Gruntfuggly.todo-tree" 17 | ], 18 | "settings": { 19 | "haskell.ghcupExecutablePath": "/home/vscode/.local/share/mise/installs/ghcup/latest/ghcup" 20 | } 21 | } 22 | } 23 | // "postCreateCommand": "sh .devcontainer/post-create.sh" 24 | } -------------------------------------------------------------------------------- /.golden/Malgo.Rename/CStyleDataDef/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/CStyleDataDef.mlg" 3 | ((((def 4 | main 5 | (fn ((clause (#CStyleDataDef.__4) (seq (do (apply Int32# (int32 42)))))))))) 6 | () 7 | ((data 8 | List 9 | (#CStyleDataDef.a_0) 10 | ((Cons (#CStyleDataDef.a_0 (app List (#CStyleDataDef.a_0)))) (Nil ()))) 11 | (data 12 | Map 13 | (#CStyleDataDef.k_1 #CStyleDataDef.v_2) 14 | ((Entry (#CStyleDataDef.k_1 #CStyleDataDef.v_2)) (Empty ()))) 15 | (data 16 | Tree 17 | (#CStyleDataDef.a_3) 18 | ((Node 19 | (#CStyleDataDef.a_3 20 | (app Tree (#CStyleDataDef.a_3)) 21 | (app Tree (#CStyleDataDef.a_3)))) 22 | (Leaf ())))) 23 | () 24 | () 25 | ((import "runtime/malgo/Builtin.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/CStyleDataDef/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/CStyleDataDef.mlg" 3 | ((((def 4 | main 5 | (fn ((clause (#CStyleDataDef.__4) (seq (do (apply Int32# (int32 42)))))))))) 6 | () 7 | ((data 8 | List 9 | (#CStyleDataDef.a_0) 10 | ((Cons (#CStyleDataDef.a_0 (app List (#CStyleDataDef.a_0)))) (Nil ()))) 11 | (data 12 | Map 13 | (#CStyleDataDef.k_1 #CStyleDataDef.v_2) 14 | ((Entry (#CStyleDataDef.k_1 #CStyleDataDef.v_2)) (Empty ()))) 15 | (data 16 | Tree 17 | (#CStyleDataDef.a_3) 18 | ((Node 19 | (#CStyleDataDef.a_3 20 | (app Tree (#CStyleDataDef.a_3)) 21 | (app Tree (#CStyleDataDef.a_3)))) 22 | (Leaf ())))) 23 | () 24 | () 25 | ((import "runtime/malgo/Builtin.mlg" all)))) -------------------------------------------------------------------------------- /test/testcases/malgo/Show.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | infixr 5 (<>) 5 | def (<>) : String -> String -> String 6 | def (<>) = { x y -> appendString x y } 7 | 8 | type Show a = { 9 | show : a -> String, 10 | } 11 | 12 | def showInt32 : Show Int32 13 | def showInt32 = { 14 | show = { x -> toStringInt32 x }, 15 | } 16 | 17 | def show : Show a -> a -> String 18 | def show = { { show = show } -> show } 19 | 20 | def showTuple2 : Show a -> Show b -> Show (a, b) 21 | def showTuple2 = { 22 | showDictA showDictB -> { 23 | show = { (a, b) -> 24 | "(" <> show showDictA a <> ", " <> show showDictB b <> ")" 25 | }, 26 | } 27 | } 28 | 29 | def printShow : Show a -> a -> () 30 | def printShow = { showDict x -> printString (show showDict x) } 31 | 32 | def main = { printShow (showTuple2 showInt32 showInt32) (1, 2) } 33 | -------------------------------------------------------------------------------- /.golden/Malgo.Rename/EmptyArguments/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/EmptyArguments.mlg" 3 | ((((def unit (fn ((clause ((tuple)) (seq (do (apply Int32# (int32 1))))))))) 4 | ((def 5 | empty 6 | (fn 7 | ((clause (#EmptyArguments.__0) (seq (do (apply Int32# (int32 0))))))))) 8 | ((def 9 | main 10 | (fn 11 | ((clause 12 | (#EmptyArguments.__1) 13 | (seq 14 | (let #EmptyArguments.x_2 (apply empty (tuple))) 15 | (let #EmptyArguments.y_3 (apply unit (tuple))) 16 | (do (apply printInt32 #EmptyArguments.x_2)) 17 | (do (apply printInt32 #EmptyArguments.y_3))))))))) 18 | () 19 | () 20 | () 21 | () 22 | ((import "runtime/malgo/Builtin.mlg" all) 23 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/EmptyArguments/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/EmptyArguments.mlg" 3 | ((((def unit (fn ((clause ((tuple)) (seq (do (apply Int32# (int32 1))))))))) 4 | ((def 5 | empty 6 | (fn 7 | ((clause (#EmptyArguments.__0) (seq (do (apply Int32# (int32 0))))))))) 8 | ((def 9 | main 10 | (fn 11 | ((clause 12 | (#EmptyArguments.__1) 13 | (seq 14 | (let #EmptyArguments.x_2 (apply empty (tuple))) 15 | (let #EmptyArguments.y_3 (apply unit (tuple))) 16 | (do (apply printInt32 #EmptyArguments.x_2)) 17 | (do (apply printInt32 #EmptyArguments.y_3))))))))) 18 | () 19 | () 20 | () 21 | () 22 | ((import "runtime/malgo/Builtin.mlg" all) 23 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/CStyleTypeSynonym/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/CStyleTypeSynonym.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#CStyleTypeSynonym.__6) 8 | (seq (do (apply Int32# (int32 42)))))))))) 9 | () 10 | () 11 | ((type IntWrapper () Int32) 12 | (type Optional (#CStyleTypeSynonym.a_0) #CStyleTypeSynonym.a_0) 13 | (type 14 | Function 15 | (#CStyleTypeSynonym.a_1 #CStyleTypeSynonym.b_2) 16 | (-> #CStyleTypeSynonym.a_1 #CStyleTypeSynonym.b_2)) 17 | (type 18 | Callback 19 | (#CStyleTypeSynonym.a_3 #CStyleTypeSynonym.b_4 #CStyleTypeSynonym.c_5) 20 | (-> 21 | #CStyleTypeSynonym.a_3 22 | (-> #CStyleTypeSynonym.b_4 #CStyleTypeSynonym.c_5)))) 23 | () 24 | ((import "runtime/malgo/Builtin.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/CStyleTypeSynonym/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/CStyleTypeSynonym.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#CStyleTypeSynonym.__6) 8 | (seq (do (apply Int32# (int32 42)))))))))) 9 | () 10 | () 11 | ((type IntWrapper () Int32) 12 | (type Optional (#CStyleTypeSynonym.a_0) #CStyleTypeSynonym.a_0) 13 | (type 14 | Function 15 | (#CStyleTypeSynonym.a_1 #CStyleTypeSynonym.b_2) 16 | (-> #CStyleTypeSynonym.a_1 #CStyleTypeSynonym.b_2)) 17 | (type 18 | Callback 19 | (#CStyleTypeSynonym.a_3 #CStyleTypeSynonym.b_4 #CStyleTypeSynonym.c_5) 20 | (-> 21 | #CStyleTypeSynonym.a_3 22 | (-> #CStyleTypeSynonym.b_4 #CStyleTypeSynonym.c_5)))) 23 | () 24 | ((import "runtime/malgo/Builtin.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToCore/SameImport/actual: -------------------------------------------------------------------------------- 1 | ((main 2 | $SameImport.return_2 3 | (cut 4 | (lambda 5 | ($SameImport.param_1 $SameImport.return_3) 6 | (cut 7 | $SameImport.param_1 8 | (select 9 | (#SameImport.__0 10 | (invoke 11 | putStr 12 | (apply 13 | ((do 14 | $SameImport.return_4 15 | (invoke 16 | getContents 17 | (apply 18 | ((construct tuple () ())) 19 | ($SameImport.return_4))))) 20 | ($SameImport.return_3))))))) 21 | $SameImport.return_2)) 22 | ("runtime/malgo/Builtin.mlg" 23 | "runtime/malgo/Builtin.mlg" 24 | "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToCore/SameImport/golden: -------------------------------------------------------------------------------- 1 | ((main 2 | $SameImport.return_2 3 | (cut 4 | (lambda 5 | ($SameImport.param_1 $SameImport.return_3) 6 | (cut 7 | $SameImport.param_1 8 | (select 9 | (#SameImport.__0 10 | (invoke 11 | putStr 12 | (apply 13 | ((do 14 | $SameImport.return_4 15 | (invoke 16 | getContents 17 | (apply 18 | ((construct tuple () ())) 19 | ($SameImport.return_4))))) 20 | ($SameImport.return_3))))))) 21 | $SameImport.return_2)) 22 | ("runtime/malgo/Builtin.mlg" 23 | "runtime/malgo/Builtin.mlg" 24 | "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/TestDot/actual: -------------------------------------------------------------------------------- 1 | (program 2 | ((succ 3 | (lambda 4 | ($TestDot.param_2) 5 | (select 6 | $TestDot.param_2 7 | (((Int64# (#TestDot.x_0)) 8 | (apply 9 | (invoke Int64#) 10 | ((apply (apply (invoke addInt64#) (#TestDot.x_0)) (1_i64))))))))) 11 | (main 12 | (lambda 13 | ($TestDot.param_3) 14 | (select 15 | $TestDot.param_3 16 | ((#TestDot.__1 17 | (apply 18 | (invoke printInt64) 19 | ((apply 20 | (apply 21 | (apply (invoke <<) ((invoke succ))) 22 | ((invoke succ))) 23 | ((apply (invoke Int64#) (0_i64)))))))))))) 24 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/TestDot/golden: -------------------------------------------------------------------------------- 1 | (program 2 | ((succ 3 | (lambda 4 | ($TestDot.param_2) 5 | (select 6 | $TestDot.param_2 7 | (((Int64# (#TestDot.x_0)) 8 | (apply 9 | (invoke Int64#) 10 | ((apply (apply (invoke addInt64#) (#TestDot.x_0)) (1_i64))))))))) 11 | (main 12 | (lambda 13 | ($TestDot.param_3) 14 | (select 15 | $TestDot.param_3 16 | ((#TestDot.__1 17 | (apply 18 | (invoke printInt64) 19 | ((apply 20 | (apply 21 | (apply (invoke <<) ((invoke succ))) 22 | ((invoke succ))) 23 | ((apply (invoke Int64#) (0_i64)))))))))))) 24 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/DeferLaw/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/DeferLaw.mlg" 3 | ((((def 4 | f 5 | (fn 6 | ((clause 7 | (#DeferLaw.x_1) 8 | (seq 9 | (do 10 | (apply 11 | (fn ((clause (#DeferLaw.__2) (seq (do #DeferLaw.x_1))))) 12 | (tuple))))))))) 13 | ((def 14 | main 15 | (fn 16 | ((clause 17 | (#DeferLaw.__3) 18 | (seq 19 | (do 20 | (apply 21 | putStrLn 22 | (apply f (apply String# (string "Hello")))))))))))) 23 | ((sig f (-> #DeferLaw.a_0 #DeferLaw.a_0))) 24 | () 25 | () 26 | () 27 | ((import "runtime/malgo/Builtin.mlg" all) 28 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/DeferLaw/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/DeferLaw.mlg" 3 | ((((def 4 | f 5 | (fn 6 | ((clause 7 | (#DeferLaw.x_1) 8 | (seq 9 | (do 10 | (apply 11 | (fn ((clause (#DeferLaw.__2) (seq (do #DeferLaw.x_1))))) 12 | (tuple))))))))) 13 | ((def 14 | main 15 | (fn 16 | ((clause 17 | (#DeferLaw.__3) 18 | (seq 19 | (do 20 | (apply 21 | putStrLn 22 | (apply f (apply String# (string "Hello")))))))))))) 23 | ((sig f (-> #DeferLaw.a_0 #DeferLaw.a_0))) 24 | () 25 | () 26 | () 27 | ((import "runtime/malgo/Builtin.mlg" all) 28 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /wiki/2025-09-04-empty-arguments.md: -------------------------------------------------------------------------------- 1 | # empty-arguments 2 | 3 | Created: 2025-09-04 4 | 5 | 空の引数について考える。 6 | 7 | ```malgo 8 | def f = { () -> 1 } 9 | f() === 1 10 | ``` 11 | 12 | カリー化との組み合わせがややこしい。 13 | 14 | まずは空の引数がない場合を考える。 15 | 16 | ```malgo 17 | def f = { (x, y) -> x + y } 18 | f(1, 2) === 3 19 | f(1) === { (y) -> 1 + y } 20 | f(1)(2) === 3 21 | f(1)(2)() // error: 3 is not a function 22 | 23 | def g = { (x) -> (y) -> x + y } 24 | f === g 25 | ``` 26 | 27 | 次に空の引数がある場合を考える。 28 | 29 | ```malgo 30 | def f = { (x, y) -> x + y } 31 | f(1, 2) === 3 32 | f(1) === { (y) -> 1 + y } 33 | f(1)(2) === 3 34 | f(1)(2)() // error: 3 is not a function 35 | 36 | def g = { (x) -> (y) -> x + y } 37 | f === g 38 | 39 | def h = { (x) -> (y) -> () -> x + y } 40 | h(1)(2)() === 3 41 | h(1, 2) === 3 or { () -> 1 + 2 } ? 42 | ``` 43 | 44 | `h(1, 2)` は `{ () -> 1 + 2 }` とするのが自然に思えるが、`f(1, 2)` と同じように `3` としたい気もする。 45 | 46 | 前者は0引数と1引数の2パターンを考慮するだけでいいが、後者は引数充足の判定が複雑になる。 -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToCore/TestExplicitModule/actual: -------------------------------------------------------------------------------- 1 | ((main 2 | $TestExplicitModule.return_2 3 | (cut 4 | (lambda 5 | ($TestExplicitModule.param_1 $TestExplicitModule.return_3) 6 | (cut 7 | $TestExplicitModule.param_1 8 | (select 9 | (#TestExplicitModule.__0 10 | (invoke 11 | putStrLn 12 | (apply 13 | ((do 14 | $TestExplicitModule.return_4 15 | (invoke 16 | String# 17 | (apply 18 | ("Hello, world") 19 | ($TestExplicitModule.return_4))))) 20 | ($TestExplicitModule.return_3))))))) 21 | $TestExplicitModule.return_2)) 22 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToCore/TestExplicitModule/golden: -------------------------------------------------------------------------------- 1 | ((main 2 | $TestExplicitModule.return_2 3 | (cut 4 | (lambda 5 | ($TestExplicitModule.param_1 $TestExplicitModule.return_3) 6 | (cut 7 | $TestExplicitModule.param_1 8 | (select 9 | (#TestExplicitModule.__0 10 | (invoke 11 | putStrLn 12 | (apply 13 | ((do 14 | $TestExplicitModule.return_4 15 | (invoke 16 | String# 17 | (apply 18 | ("Hello, world") 19 | ($TestExplicitModule.return_4))))) 20 | ($TestExplicitModule.return_3))))))) 21 | $TestExplicitModule.return_2)) 22 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /examples/malgo/List.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../runtime/malgo/Prelude.mlg" 3 | 4 | infix 4 (<=) 5 | def (<=) : Int32 -> Int32 -> Bool 6 | def (<=) = {x y -> leInt32 x y} 7 | 8 | infixl 6 (+) 9 | def (+) : Int32 -> Int32 -> Int32 10 | def (+) = {x y -> addInt32 x y} 11 | 12 | infixl 6 (-) 13 | def (-) : Int32 -> Int32 -> Int32 14 | def (-) = {x y -> subInt32 x y} 15 | 16 | def map : (a -> b) -> List a -> List b 17 | def map = 18 | { _ Nil -> Nil, 19 | f (Cons x xs) -> Cons (f x) (map f xs) 20 | } 21 | 22 | def sum : List Int32 -> Int32 23 | def sum = 24 | { Nil -> 0, 25 | (Cons x xs) -> x + sum xs 26 | } 27 | 28 | -- [0 .. n] 29 | def below : Int32 -> List Int32 30 | def below = { n -> 31 | if (n <= 0) 32 | { [0] } 33 | { Cons n (below (n - 1)) } 34 | } 35 | 36 | def main = { 37 | sum (map (addInt32 1) (below 10)) 38 | |> toStringInt32 39 | |> putStrLn 40 | } 41 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/DataDef/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/DataDef.mlg" 3 | ((data Int () ((Int# (Int64#)))) 4 | (data List (a) ((Nil ()) (Cons (a (app List (a)))))) 5 | (foreign malgo_int64_t_to_string (-> Int64# String#)) 6 | (foreign malgo_print_string (-> String# (tuple))) 7 | (def 8 | main 9 | (fn 10 | ((clause 11 | (_) 12 | (seq 13 | (do 14 | (apply 15 | (fn 16 | ((clause 17 | ((con Int# (x))) 18 | (seq 19 | (do 20 | (apply 21 | malgo_print_string 22 | (apply malgo_int64_t_to_string x))))))) 23 | (apply Int# (int64 1))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/DataDef/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/DataDef.mlg" 3 | ((data Int () ((Int# (Int64#)))) 4 | (data List (a) ((Nil ()) (Cons (a (app List (a)))))) 5 | (foreign malgo_int64_t_to_string (-> Int64# String#)) 6 | (foreign malgo_print_string (-> String# (tuple))) 7 | (def 8 | main 9 | (fn 10 | ((clause 11 | (_) 12 | (seq 13 | (do 14 | (apply 15 | (fn 16 | ((clause 17 | ((con Int# (x))) 18 | (seq 19 | (do 20 | (apply 21 | malgo_print_string 22 | (apply malgo_int64_t_to_string x))))))) 23 | (apply Int# (int64 1))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/Ones/actual: -------------------------------------------------------------------------------- 1 | (program 2 | ((ones (object ((head (apply (invoke Int32#) (1_i32))) (tail (invoke ones))))) 3 | (main 4 | (lambda 5 | ($Ones.param_1) 6 | (select 7 | $Ones.param_1 8 | ((#Ones.__0 9 | (apply 10 | (invoke printString) 11 | ((apply 12 | (invoke toStringInt32) 13 | ((project 14 | (project 15 | (project 16 | (project 17 | (project (project (invoke ones) tail) tail) 18 | tail) 19 | tail) 20 | tail) 21 | head))))))))))) 22 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/Ones/golden: -------------------------------------------------------------------------------- 1 | (program 2 | ((ones (object ((head (apply (invoke Int32#) (1_i32))) (tail (invoke ones))))) 3 | (main 4 | (lambda 5 | ($Ones.param_1) 6 | (select 7 | $Ones.param_1 8 | ((#Ones.__0 9 | (apply 10 | (invoke printString) 11 | ((apply 12 | (invoke toStringInt32) 13 | ((project 14 | (project 15 | (project 16 | (project 17 | (project (project (invoke ones) tail) tail) 18 | tail) 19 | tail) 20 | tail) 21 | head))))))))))) 22 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/FuncOverUnboxed/actual: -------------------------------------------------------------------------------- 1 | (program 2 | ((f 3 | (lambda 4 | ($FuncOverUnboxed.param_2) 5 | (select 6 | $FuncOverUnboxed.param_2 7 | ((0_i64 8 | (apply 9 | (invoke printString#) 10 | ((apply (invoke toStringInt64#) (1_i64))))) 11 | (1_i64 12 | (apply 13 | (invoke printString#) 14 | ((apply (invoke toStringInt64#) (1_i64))))) 15 | (#FuncOverUnboxed.__0 16 | (apply 17 | (invoke printString#) 18 | ((apply (invoke toStringInt64#) (0_i64))))))))) 19 | (main 20 | (lambda 21 | ($FuncOverUnboxed.param_3) 22 | (select 23 | $FuncOverUnboxed.param_3 24 | ((#FuncOverUnboxed.__1 (apply (invoke f) (0_i64)))))))) 25 | ("runtime/malgo/Builtin.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/FuncOverUnboxed/golden: -------------------------------------------------------------------------------- 1 | (program 2 | ((f 3 | (lambda 4 | ($FuncOverUnboxed.param_2) 5 | (select 6 | $FuncOverUnboxed.param_2 7 | ((0_i64 8 | (apply 9 | (invoke printString#) 10 | ((apply (invoke toStringInt64#) (1_i64))))) 11 | (1_i64 12 | (apply 13 | (invoke printString#) 14 | ((apply (invoke toStringInt64#) (1_i64))))) 15 | (#FuncOverUnboxed.__0 16 | (apply 17 | (invoke printString#) 18 | ((apply (invoke toStringInt64#) (0_i64))))))))) 19 | (main 20 | (lambda 21 | ($FuncOverUnboxed.param_3) 22 | (select 23 | $FuncOverUnboxed.param_3 24 | ((#FuncOverUnboxed.__1 (apply (invoke f) (0_i64)))))))) 25 | ("runtime/malgo/Builtin.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/TestDot/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/TestDot.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (def 6 | succ 7 | (fn 8 | ((clause 9 | ((con Int64# (x))) 10 | (seq 11 | (do 12 | (parens 13 | (apply 14 | Int64# 15 | (parens (apply (apply addInt64# x) (int64 1))))))))))) 16 | (def 17 | main 18 | (fn 19 | ((clause 20 | (_) 21 | (seq 22 | (do 23 | (apply 24 | printInt64 25 | (parens 26 | (apply 27 | (parens (opapp << succ succ)) 28 | (parens (apply Int64# (int64 0)))))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/TestDot/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/TestDot.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (def 6 | succ 7 | (fn 8 | ((clause 9 | ((con Int64# (x))) 10 | (seq 11 | (do 12 | (parens 13 | (apply 14 | Int64# 15 | (parens (apply (apply addInt64# x) (int64 1))))))))))) 16 | (def 17 | main 18 | (fn 19 | ((clause 20 | (_) 21 | (seq 22 | (do 23 | (apply 24 | printInt64 25 | (parens 26 | (apply 27 | (parens (opapp << succ succ)) 28 | (parens (apply Int64# (int64 0)))))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToCore/Echo/flat/actual: -------------------------------------------------------------------------------- 1 | ((main 2 | $Echo.return_2 3 | (cut 4 | (lambda 5 | ($Echo.param_1 $Echo.return_3) 6 | (cut 7 | $Echo.param_1 8 | (select 9 | (#Echo.__0 10 | (invoke 11 | putStr 12 | (then 13 | $Echo.outer_5 14 | (join 15 | $Echo.return_4 16 | (then 17 | $Echo.inner_6 18 | (cut 19 | $Echo.outer_5 20 | (apply ($Echo.inner_6) ($Echo.return_3)))) 21 | (invoke 22 | getContents 23 | (apply ((construct tuple () ())) ($Echo.return_4)))))))))) 24 | $Echo.return_2)) 25 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToCore/Echo/flat/golden: -------------------------------------------------------------------------------- 1 | ((main 2 | $Echo.return_2 3 | (cut 4 | (lambda 5 | ($Echo.param_1 $Echo.return_3) 6 | (cut 7 | $Echo.param_1 8 | (select 9 | (#Echo.__0 10 | (invoke 11 | putStr 12 | (then 13 | $Echo.outer_5 14 | (join 15 | $Echo.return_4 16 | (then 17 | $Echo.inner_6 18 | (cut 19 | $Echo.outer_5 20 | (apply ($Echo.inner_6) ($Echo.return_3)))) 21 | (invoke 22 | getContents 23 | (apply ((construct tuple () ())) ($Echo.return_4)))))))))) 24 | $Echo.return_2)) 25 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /test/Malgo/ParserSpec/errors/InvalidOperator.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | -- `=>` is not allowed as operator 5 | infix 4 (=>) 6 | def (=>) = { x y -> leInt32 y x } 7 | 8 | infixl 6 (+) 9 | def (+) = { x y -> addInt32 x y } 10 | 11 | infixl 6 (-) 12 | def (-) = { x y -> subInt32 x y } 13 | 14 | def fib = { n -> 15 | if (n => 1) 16 | { 1 } 17 | { fib (n - 1) + fib (n - 2) } 18 | } 19 | 20 | def main = { 21 | fib 5 |> toStringInt32 |> putStrLn 22 | } 23 | foreign import malgo_print_string : String# -> () 24 | foreign import malgo_newline : () -> () 25 | 26 | data String = String# String# 27 | 28 | -- `let` does not allowed as identifier 29 | def let : String -> () 30 | def let = { (String# str) -> 31 | malgo_print_string str; 32 | malgo_newline () 33 | } 34 | 35 | def string# : String# -> String 36 | def string# = { x -> String# x } 37 | 38 | def main = { 39 | let "Hello, world" 40 | } 41 | -------------------------------------------------------------------------------- /.golden/Malgo.Parser/HelloImport/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/HelloImport.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (sig main (block (tuple))) 6 | (def 7 | main 8 | (fn 9 | ((clause 10 | (_) 11 | (seq 12 | (do (apply putStr (parens (apply String# (string "hello"))))) 13 | (do 14 | (opapp 15 | |> 16 | putStrLn 17 | (fn 18 | ((clause 19 | (f) 20 | (seq 21 | (do 22 | (apply 23 | f 24 | (parens 25 | (apply String# (string " world")))))))))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/HelloImport/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/HelloImport.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (sig main (block (tuple))) 6 | (def 7 | main 8 | (fn 9 | ((clause 10 | (_) 11 | (seq 12 | (do (apply putStr (parens (apply String# (string "hello"))))) 13 | (do 14 | (opapp 15 | |> 16 | putStrLn 17 | (fn 18 | ((clause 19 | (f) 20 | (seq 21 | (do 22 | (apply 23 | f 24 | (parens 25 | (apply String# (string " world")))))))))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/EmptyConstructor/actual: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($EmptyConstructor.param_3) 5 | (select 6 | $EmptyConstructor.param_3 7 | ((#EmptyConstructor.__0 8 | (let 9 | #EmptyConstructor.x_1 10 | (invoke Empty) 11 | (let 12 | #EmptyConstructor.y_2 13 | (apply (invoke Unit) ((tuple ()))) 14 | (apply 15 | (lambda 16 | ($EmptyConstructor.tmp_4) 17 | (apply (invoke print) (#EmptyConstructor.y_2))) 18 | ((apply (invoke print) (#EmptyConstructor.x_1))))))))))) 19 | (Empty (Empty ())) 20 | (Unit 21 | (lambda 22 | ($EmptyConstructor.constructor_5) 23 | (Unit ($EmptyConstructor.constructor_5))))) 24 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/EmptyConstructor/golden: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($EmptyConstructor.param_3) 5 | (select 6 | $EmptyConstructor.param_3 7 | ((#EmptyConstructor.__0 8 | (let 9 | #EmptyConstructor.x_1 10 | (invoke Empty) 11 | (let 12 | #EmptyConstructor.y_2 13 | (apply (invoke Unit) ((tuple ()))) 14 | (apply 15 | (lambda 16 | ($EmptyConstructor.tmp_4) 17 | (apply (invoke print) (#EmptyConstructor.y_2))) 18 | ((apply (invoke print) (#EmptyConstructor.x_1))))))))))) 19 | (Empty (Empty ())) 20 | (Unit 21 | (lambda 22 | ($EmptyConstructor.constructor_5) 23 | (Unit ($EmptyConstructor.constructor_5))))) 24 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /examples/malgo/Vector.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../runtime/malgo/Prelude.mlg" 3 | 4 | foreign import malgo_new_vector : Int64# -> Ptr# Char# -> Ptr# (Ptr# Char#) 5 | 6 | foreign import malgo_read_vector : Int64# -> Ptr# (Ptr# Char#) -> Ptr# Char# 7 | 8 | data Vector a = Vector Int64 (Ptr# a) 9 | 10 | def newVector : Int64 -> a -> Vector a 11 | def newVector = { (Int64# length) init -> 12 | Vector (Int64# length) (malgo_unsafe_cast (malgo_new_vector length (malgo_unsafe_cast init))) 13 | } 14 | 15 | def readVector : Int64 -> Vector a -> Maybe a 16 | def readVector = { (Int64# index) (Vector (Int64# length) ptr) -> 17 | if (isTrue# (geInt64# index length)) 18 | { Nothing } 19 | { Just (malgo_unsafe_cast (malgo_read_vector index (malgo_unsafe_cast ptr))) } 20 | } 21 | 22 | def main = { 23 | let vec = newVector 10i64 5; 24 | let val = readVector 2i64 vec; 25 | val |> { Nothing -> putStrLn "ERROR", 26 | Just x -> putStrLn (toStringInt32 x) } 27 | } -------------------------------------------------------------------------------- /.golden/Malgo.Rename/Pragma/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Pragma.mlg" 3 | ((((def 4 | string# 5 | (fn ((clause (#Pragma.x_1) (seq (do (apply String# #Pragma.x_1)))))))) 6 | ((def 7 | putStrLn 8 | (fn 9 | ((clause 10 | ((con String# (#Pragma.str_0))) 11 | (seq 12 | (do (apply malgo_print_string #Pragma.str_0)) 13 | (do (apply malgo_newline (tuple))))))))) 14 | ((def 15 | main 16 | (fn 17 | ((clause 18 | (#Pragma.__2) 19 | (seq 20 | (do (apply putStrLn (apply String# (string "Hello, world"))))))))))) 21 | ((sig putStrLn (-> String (tuple))) (sig string# (-> String# String))) 22 | ((data String () ((String# (String#))))) 23 | () 24 | ((foreign malgo_print_string (-> String# (tuple))) 25 | (foreign malgo_newline (-> (tuple) (tuple)))) 26 | ())) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/Pragma/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Pragma.mlg" 3 | ((((def 4 | string# 5 | (fn ((clause (#Pragma.x_1) (seq (do (apply String# #Pragma.x_1)))))))) 6 | ((def 7 | putStrLn 8 | (fn 9 | ((clause 10 | ((con String# (#Pragma.str_0))) 11 | (seq 12 | (do (apply malgo_print_string #Pragma.str_0)) 13 | (do (apply malgo_newline (tuple))))))))) 14 | ((def 15 | main 16 | (fn 17 | ((clause 18 | (#Pragma.__2) 19 | (seq 20 | (do (apply putStrLn (apply String# (string "Hello, world"))))))))))) 21 | ((sig putStrLn (-> String (tuple))) (sig string# (-> String# String))) 22 | ((data String () ((String# (String#))))) 23 | () 24 | ((foreign malgo_print_string (-> String# (tuple))) 25 | (foreign malgo_newline (-> (tuple) (tuple)))) 26 | ())) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/HelloImport/actual: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($HelloImport.param_2) 5 | (select 6 | $HelloImport.param_2 7 | ((#HelloImport.__0 8 | (apply 9 | (lambda 10 | ($HelloImport.tmp_3) 11 | (apply 12 | (apply (invoke |>) ((invoke putStrLn))) 13 | ((lambda 14 | ($HelloImport.param_4) 15 | (select 16 | $HelloImport.param_4 17 | ((#HelloImport.f_1 18 | (apply 19 | #HelloImport.f_1 20 | ((apply (invoke String#) (" world"))))))))))) 21 | ((apply (invoke putStr) ((apply (invoke String#) ("hello")))))))))))) 22 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/HelloImport/golden: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($HelloImport.param_2) 5 | (select 6 | $HelloImport.param_2 7 | ((#HelloImport.__0 8 | (apply 9 | (lambda 10 | ($HelloImport.tmp_3) 11 | (apply 12 | (apply (invoke |>) ((invoke putStrLn))) 13 | ((lambda 14 | ($HelloImport.param_4) 15 | (select 16 | $HelloImport.param_4 17 | ((#HelloImport.f_1 18 | (apply 19 | #HelloImport.f_1 20 | ((apply (invoke String#) (" world"))))))))))) 21 | ((apply (invoke putStr) ((apply (invoke String#) ("hello")))))))))))) 22 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/TuplePattern/actual: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($TuplePattern.param_4) 5 | (select 6 | $TuplePattern.param_4 7 | ((#TuplePattern.__0 8 | (apply 9 | (apply (invoke |>) ((tuple ((invoke A) (invoke B))))) 10 | ((lambda 11 | ($TuplePattern.param_5) 12 | (select 13 | $TuplePattern.param_5 14 | (((tuple ((A ()) #TuplePattern.rest_1)) 15 | (apply 16 | (invoke printString) 17 | ((apply (invoke String#) ("A"))))) 18 | ((tuple ((B ()) #TuplePattern.rest_2)) (tuple ())) 19 | ((tuple ((C ()) #TuplePattern.rest_3)) (tuple ())))))))))))) 20 | (A (A ())) 21 | (B (B ())) 22 | (C (C ()))) 23 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/TuplePattern/golden: -------------------------------------------------------------------------------- 1 | (program 2 | ((main 3 | (lambda 4 | ($TuplePattern.param_4) 5 | (select 6 | $TuplePattern.param_4 7 | ((#TuplePattern.__0 8 | (apply 9 | (apply (invoke |>) ((tuple ((invoke A) (invoke B))))) 10 | ((lambda 11 | ($TuplePattern.param_5) 12 | (select 13 | $TuplePattern.param_5 14 | (((tuple ((A ()) #TuplePattern.rest_1)) 15 | (apply 16 | (invoke printString) 17 | ((apply (invoke String#) ("A"))))) 18 | ((tuple ((B ()) #TuplePattern.rest_2)) (tuple ())) 19 | ((tuple ((C ()) #TuplePattern.rest_3)) (tuple ())))))))))))) 20 | (A (A ())) 21 | (B (B ())) 22 | (C (C ()))) 23 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/TypeAnnotation/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/TypeAnnotation.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#TypeAnnotation.__0) 8 | (seq 9 | (do 10 | (apply 11 | printString 12 | (parens 13 | (apply 14 | (parens 15 | (ann 16 | (fn 17 | ((clause 18 | (#TypeAnnotation.x_1) 19 | (seq (do #TypeAnnotation.x_1))))) 20 | (-> String String))) 21 | (apply String# (string "hoge"))))))))))))) 22 | () 23 | () 24 | () 25 | () 26 | ((import "runtime/malgo/Builtin.mlg" all) 27 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/TypeAnnotation/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/TypeAnnotation.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#TypeAnnotation.__0) 8 | (seq 9 | (do 10 | (apply 11 | printString 12 | (parens 13 | (apply 14 | (parens 15 | (ann 16 | (fn 17 | ((clause 18 | (#TypeAnnotation.x_1) 19 | (seq (do #TypeAnnotation.x_1))))) 20 | (-> String String))) 21 | (apply String# (string "hoge"))))))))))))) 22 | () 23 | () 24 | () 25 | () 26 | ((import "runtime/malgo/Builtin.mlg" all) 27 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/RecordFieldAccess/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/RecordFieldAccess.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (data B () ((B ((record (a Int32) (b Int32)))))) 6 | (def f (fn ((clause ((record (a a) (b _))) (seq (do a)))))) 7 | (def g (fn ((clause (B (record (a a) (b _))) (seq (do a)))))) 8 | (def 9 | main 10 | (fn 11 | ((clause 12 | (_) 13 | (seq 14 | (let x (record (a (int32 32)) (b (int32 10)))) 15 | (do 16 | (apply 17 | printString 18 | (parens 19 | (apply 20 | toStringInt32 21 | (parens 22 | (apply 23 | (apply addInt32 (parens (apply f x))) 24 | (project x "b")))))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/RecordFieldAccess/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/RecordFieldAccess.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (import "runtime/malgo/Prelude.mlg" all) 5 | (data B () ((B ((record (a Int32) (b Int32)))))) 6 | (def f (fn ((clause ((record (a a) (b _))) (seq (do a)))))) 7 | (def g (fn ((clause (B (record (a a) (b _))) (seq (do a)))))) 8 | (def 9 | main 10 | (fn 11 | ((clause 12 | (_) 13 | (seq 14 | (let x (record (a (int32 32)) (b (int32 10)))) 15 | (do 16 | (apply 17 | printString 18 | (parens 19 | (apply 20 | toStringInt32 21 | (parens 22 | (apply 23 | (apply addInt32 (parens (apply f x))) 24 | (project x "b")))))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/Test0/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Test0.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (infix left 0 |>) 5 | (sig |> (-> a (-> (-> a b) b))) 6 | (def |> (fn ((clause (x f) (seq (do (apply f x))))))) 7 | (infix left 6 +#) 8 | (def +# (fn ((clause (x y) (seq (do (apply (apply addInt64# x) y))))))) 9 | (def 10 | main 11 | (fn 12 | ((clause 13 | (_) 14 | (seq 15 | (do 16 | (opapp 17 | |> 18 | (apply Int64# (int64 1)) 19 | (fn 20 | ((clause 21 | ((con Int64# (i))) 22 | (seq 23 | (do 24 | (apply 25 | printString# 26 | (parens (apply toStringInt64# i))))))))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/Test0/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Test0.mlg" 3 | ((import "runtime/malgo/Builtin.mlg" all) 4 | (infix left 0 |>) 5 | (sig |> (-> a (-> (-> a b) b))) 6 | (def |> (fn ((clause (x f) (seq (do (apply f x))))))) 7 | (infix left 6 +#) 8 | (def +# (fn ((clause (x y) (seq (do (apply (apply addInt64# x) y))))))) 9 | (def 10 | main 11 | (fn 12 | ((clause 13 | (_) 14 | (seq 15 | (do 16 | (opapp 17 | |> 18 | (apply Int64# (int64 1)) 19 | (fn 20 | ((clause 21 | ((con Int64# (i))) 22 | (seq 23 | (do 24 | (apply 25 | printString# 26 | (parens (apply toStringInt64# i))))))))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/Seq/actual: -------------------------------------------------------------------------------- 1 | (program 2 | ((executeWhenLoaded 3 | (let 4 | #Seq.x_0 5 | (apply (invoke Int32#) (1_i32)) 6 | (let 7 | #Seq.y_1 8 | (apply (invoke Int32#) (2_i32)) 9 | (apply 10 | (lambda 11 | ($Seq.tmp_3) 12 | (apply (apply (invoke addInt32) (#Seq.x_0)) (#Seq.y_1))) 13 | ((apply 14 | (invoke printString) 15 | ((apply 16 | (invoke toStringInt32) 17 | ((apply (apply (invoke addInt32) (#Seq.x_0)) (#Seq.y_1))))))))))) 18 | (main 19 | (lambda 20 | ($Seq.param_4) 21 | (select 22 | $Seq.param_4 23 | ((#Seq.__2 24 | (apply 25 | (invoke printString) 26 | ((apply (invoke toStringInt32) ((invoke executeWhenLoaded))))))))))) 27 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/Seq/golden: -------------------------------------------------------------------------------- 1 | (program 2 | ((executeWhenLoaded 3 | (let 4 | #Seq.x_0 5 | (apply (invoke Int32#) (1_i32)) 6 | (let 7 | #Seq.y_1 8 | (apply (invoke Int32#) (2_i32)) 9 | (apply 10 | (lambda 11 | ($Seq.tmp_3) 12 | (apply (apply (invoke addInt32) (#Seq.x_0)) (#Seq.y_1))) 13 | ((apply 14 | (invoke printString) 15 | ((apply 16 | (invoke toStringInt32) 17 | ((apply (apply (invoke addInt32) (#Seq.x_0)) (#Seq.y_1))))))))))) 18 | (main 19 | (lambda 20 | ($Seq.param_4) 21 | (select 22 | $Seq.param_4 23 | ((#Seq.__2 24 | (apply 25 | (invoke printString) 26 | ((apply (invoke toStringInt32) ((invoke executeWhenLoaded))))))))))) 27 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/Test2/actual: -------------------------------------------------------------------------------- 1 | (program 2 | ((rtob 3 | (lambda 4 | ($Test2.param_3) 5 | (select $Test2.param_3 (((R ()) (invoke B)) (#Test2.a_0 #Test2.a_0))))) 6 | (main 7 | (lambda 8 | ($Test2.param_4) 9 | (select 10 | $Test2.param_4 11 | ((#Test2.__1 12 | (apply 13 | (lambda 14 | ($Test2.param_5) 15 | (select 16 | $Test2.param_5 17 | (((B ()) (apply (invoke malgo_print_string) ("OK"))) 18 | (#Test2.__2 19 | (apply (invoke malgo_print_string) ("WRONG")))))) 20 | ((apply (invoke rtob) ((invoke R)))))))))) 21 | (R (R ())) 22 | (G (G ())) 23 | (B (B ())) 24 | (malgo_print_string 25 | (lambda 26 | ($Test2.primitive_6) 27 | (primitive malgo_print_string ($Test2.primitive_6))))) 28 | ()) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/Test2/golden: -------------------------------------------------------------------------------- 1 | (program 2 | ((rtob 3 | (lambda 4 | ($Test2.param_3) 5 | (select $Test2.param_3 (((R ()) (invoke B)) (#Test2.a_0 #Test2.a_0))))) 6 | (main 7 | (lambda 8 | ($Test2.param_4) 9 | (select 10 | $Test2.param_4 11 | ((#Test2.__1 12 | (apply 13 | (lambda 14 | ($Test2.param_5) 15 | (select 16 | $Test2.param_5 17 | (((B ()) (apply (invoke malgo_print_string) ("OK"))) 18 | (#Test2.__2 19 | (apply (invoke malgo_print_string) ("WRONG")))))) 20 | ((apply (invoke rtob) ((invoke R)))))))))) 21 | (R (R ())) 22 | (G (G ())) 23 | (B (B ())) 24 | (malgo_print_string 25 | (lambda 26 | ($Test2.primitive_6) 27 | (primitive malgo_print_string ($Test2.primitive_6))))) 28 | ()) -------------------------------------------------------------------------------- /src/Malgo/Rename/RnState.hs: -------------------------------------------------------------------------------- 1 | module Malgo.Rename.RnState (RnState (..)) where 2 | 3 | import Data.Map.Strict qualified as Map 4 | import Data.Set qualified as Set 5 | import Malgo.Module 6 | import Malgo.Prelude 7 | import Malgo.Syntax.Extension 8 | import Prettyprinter (braces, sep, (<+>)) 9 | 10 | data RnState = RnState 11 | { infixInfo :: Map RnId (Assoc, Int), 12 | dependencies :: Set ModuleName, 13 | exportedIdentifiers :: [PsId], 14 | exportedTypeIdentifiers :: [PsId] 15 | } 16 | deriving stock (Show) 17 | 18 | instance Pretty RnState where 19 | pretty RnState {infixInfo, dependencies, exportedIdentifiers, exportedTypeIdentifiers} = 20 | "RnState" 21 | <+> braces 22 | ( sep 23 | [ sep ["infixInfo", "=", pretty $ Map.toList infixInfo], 24 | sep ["dependencies", "=", pretty $ Set.toList dependencies], 25 | sep ["exportedIdentifiers", "=", pretty exportedIdentifiers], 26 | sep ["exportedTypeIdentifiers", "=", pretty exportedTypeIdentifiers] 27 | ] 28 | ) 29 | -------------------------------------------------------------------------------- /.golden/Malgo.Rename/HelloBoxed/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/HelloBoxed.mlg" 3 | ((((def 4 | string# 5 | (fn 6 | ((clause (#HelloBoxed.x_1) (seq (do (apply String# #HelloBoxed.x_1)))))))) 7 | ((def 8 | putStrLn 9 | (fn 10 | ((clause 11 | ((con String# (#HelloBoxed.str_0))) 12 | (seq 13 | (do (apply malgo_print_string #HelloBoxed.str_0)) 14 | (do (apply malgo_newline (tuple))))))))) 15 | ((def 16 | main 17 | (fn 18 | ((clause 19 | (#HelloBoxed.__2) 20 | (seq 21 | (do (apply putStrLn (apply String# (string "Hello, world"))))))))))) 22 | ((sig putStrLn (-> String (tuple))) (sig string# (-> String# String))) 23 | ((data String () ((String# (String#))))) 24 | () 25 | ((foreign malgo_print_string (-> String# (tuple))) 26 | (foreign malgo_newline (-> (tuple) (tuple)))) 27 | ())) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/HelloBoxed/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/HelloBoxed.mlg" 3 | ((((def 4 | string# 5 | (fn 6 | ((clause (#HelloBoxed.x_1) (seq (do (apply String# #HelloBoxed.x_1)))))))) 7 | ((def 8 | putStrLn 9 | (fn 10 | ((clause 11 | ((con String# (#HelloBoxed.str_0))) 12 | (seq 13 | (do (apply malgo_print_string #HelloBoxed.str_0)) 14 | (do (apply malgo_newline (tuple))))))))) 15 | ((def 16 | main 17 | (fn 18 | ((clause 19 | (#HelloBoxed.__2) 20 | (seq 21 | (do (apply putStrLn (apply String# (string "Hello, world"))))))))))) 22 | ((sig putStrLn (-> String (tuple))) (sig string# (-> String# String))) 23 | ((data String () ((String# (String#))))) 24 | () 25 | ((foreign malgo_print_string (-> String# (tuple))) 26 | (foreign malgo_newline (-> (tuple) (tuple)))) 27 | ())) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToCore/Pattern/actual: -------------------------------------------------------------------------------- 1 | ((main 2 | $Pattern.return_4 3 | (cut 4 | (lambda 5 | ($Pattern.param_2 $Pattern.return_5) 6 | (cut 7 | $Pattern.param_2 8 | (select 9 | (#Pattern.__1 10 | (invoke 11 | putStrLn 12 | (apply 13 | ((do 14 | $Pattern.return_6 15 | (invoke String# (apply ("OK") ($Pattern.return_6))))) 16 | ($Pattern.return_5))))))) 17 | $Pattern.return_4)) 18 | (isNil 19 | $Pattern.return_7 20 | (cut 21 | (lambda 22 | ($Pattern.param_3 $Pattern.return_8) 23 | (cut 24 | $Pattern.param_3 25 | (select 26 | ((Nil ()) (invoke True $Pattern.return_8)) 27 | (#Pattern.__0 (invoke False $Pattern.return_8))))) 28 | $Pattern.return_7)) 29 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToCore/Pattern/golden: -------------------------------------------------------------------------------- 1 | ((main 2 | $Pattern.return_4 3 | (cut 4 | (lambda 5 | ($Pattern.param_2 $Pattern.return_5) 6 | (cut 7 | $Pattern.param_2 8 | (select 9 | (#Pattern.__1 10 | (invoke 11 | putStrLn 12 | (apply 13 | ((do 14 | $Pattern.return_6 15 | (invoke String# (apply ("OK") ($Pattern.return_6))))) 16 | ($Pattern.return_5))))))) 17 | $Pattern.return_4)) 18 | (isNil 19 | $Pattern.return_7 20 | (cut 21 | (lambda 22 | ($Pattern.param_3 $Pattern.return_8) 23 | (cut 24 | $Pattern.param_3 25 | (select 26 | ((Nil ()) (invoke True $Pattern.return_8)) 27 | (#Pattern.__0 (invoke False $Pattern.return_8))))) 28 | $Pattern.return_7)) 29 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToCore/Double/actual: -------------------------------------------------------------------------------- 1 | ((main 2 | $Double.return_2 3 | (cut 4 | (lambda 5 | ($Double.param_1 $Double.return_3) 6 | (cut 7 | $Double.param_1 8 | (select 9 | (#Double.__0 10 | (invoke 11 | putStr 12 | (apply 13 | ((do 14 | $Double.return_4 15 | (invoke 16 | toStringDouble 17 | (apply 18 | ((do 19 | $Double.return_5 20 | (invoke 21 | Double# 22 | (apply (3.14_f64) ($Double.return_5))))) 23 | ($Double.return_4))))) 24 | ($Double.return_3))))))) 25 | $Double.return_2)) 26 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToCore/Double/golden: -------------------------------------------------------------------------------- 1 | ((main 2 | $Double.return_2 3 | (cut 4 | (lambda 5 | ($Double.param_1 $Double.return_3) 6 | (cut 7 | $Double.param_1 8 | (select 9 | (#Double.__0 10 | (invoke 11 | putStr 12 | (apply 13 | ((do 14 | $Double.return_4 15 | (invoke 16 | toStringDouble 17 | (apply 18 | ((do 19 | $Double.return_5 20 | (invoke 21 | Double# 22 | (apply (3.14_f64) ($Double.return_5))))) 23 | ($Double.return_4))))) 24 | ($Double.return_3))))))) 25 | $Double.return_2)) 26 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/TestPolySynonym/actual: -------------------------------------------------------------------------------- 1 | (program 2 | ((first 3 | (lambda 4 | ($TestPolySynonym.param_9) 5 | (select 6 | $TestPolySynonym.param_9 7 | (((expand ((fst #TestPolySynonym.x_5) (snd #TestPolySynonym.__6))) 8 | #TestPolySynonym.x_5))))) 9 | (main 10 | (lambda 11 | ($TestPolySynonym.param_10) 12 | (select 13 | $TestPolySynonym.param_10 14 | ((#TestPolySynonym.__7 15 | (let 16 | #TestPolySynonym.x_8 17 | (object 18 | ((fst (apply (invoke Int32#) (1_i32))) 19 | (snd (apply (invoke String#) ("hoge"))))) 20 | (apply 21 | (apply 22 | (invoke |>) 23 | ((apply (invoke first) (#TestPolySynonym.x_8)))) 24 | ((invoke printInt32)))))))))) 25 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /.golden/Malgo.Sequent.ToFun/TestPolySynonym/golden: -------------------------------------------------------------------------------- 1 | (program 2 | ((first 3 | (lambda 4 | ($TestPolySynonym.param_9) 5 | (select 6 | $TestPolySynonym.param_9 7 | (((expand ((fst #TestPolySynonym.x_5) (snd #TestPolySynonym.__6))) 8 | #TestPolySynonym.x_5))))) 9 | (main 10 | (lambda 11 | ($TestPolySynonym.param_10) 12 | (select 13 | $TestPolySynonym.param_10 14 | ((#TestPolySynonym.__7 15 | (let 16 | #TestPolySynonym.x_8 17 | (object 18 | ((fst (apply (invoke Int32#) (1_i32))) 19 | (snd (apply (invoke String#) ("hoge"))))) 20 | (apply 21 | (apply 22 | (invoke |>) 23 | ((apply (invoke first) (#TestPolySynonym.x_8)))) 24 | ((invoke printInt32)))))))))) 25 | ("runtime/malgo/Builtin.mlg" "runtime/malgo/Prelude.mlg")) -------------------------------------------------------------------------------- /test/testcases/malgo/RightAssoc.mlg: -------------------------------------------------------------------------------- 1 | module {..} = import "../../../runtime/malgo/Builtin.mlg" 2 | module {..} = import "../../../runtime/malgo/Prelude.mlg" 3 | 4 | infixr 2 (<|>) 5 | def (<|>) : a -> List a -> List a 6 | def (<|>) = Cons 7 | 8 | def f = { n -> 9 | -- fixed: https://github.com/malgo-lang/malgo/commit/b499a897271ea32ffe55d5e15aaa0e3138479f58 10 | 11 | -- slow 12 | let x = (True, { 1 }) 13 | <|> ((True, { 2 }) 14 | <|> ((True, { 3 }) 15 | <|> ((True, { 4 }) 16 | <|> Nil))); 17 | 18 | -- fast, but type error on (True, { 3 }) 19 | let y = (True, { 1 }) 20 | <|> (True, { 2 }) 21 | <|> (True, { 3 }) 22 | <|> (True, { 4 }) 23 | <|> Nil; 24 | y 25 | 26 | -- fast 27 | -- (True, { 1 }) 28 | -- <|> (True, { 2 }) 29 | -- <|> ((True, { 3 }) 30 | -- <|> (True, { 4 }) 31 | -- <|> Nil) 32 | } 33 | 34 | def main : { () } 35 | def main = { 36 | let x = f 4; 37 | printString "OK" 38 | } 39 | -------------------------------------------------------------------------------- /.golden/Malgo.Rename/Seq/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Seq.mlg" 3 | ((((def 4 | executeWhenLoaded 5 | (seq 6 | (let #Seq.x_0 (apply Int32# (int32 1))) 7 | (let #Seq.y_1 (apply Int32# (int32 2))) 8 | (do 9 | (apply 10 | printString 11 | (parens 12 | (apply 13 | toStringInt32 14 | (parens (apply (apply addInt32 #Seq.x_0) #Seq.y_1)))))) 15 | (do (apply (apply addInt32 #Seq.x_0) #Seq.y_1))))) 16 | ((def 17 | main 18 | (fn 19 | ((clause 20 | (#Seq.__2) 21 | (seq 22 | (do 23 | (apply 24 | printString 25 | (parens (apply toStringInt32 executeWhenLoaded))))))))))) 26 | () 27 | () 28 | () 29 | () 30 | ((import "runtime/malgo/Builtin.mlg" all) 31 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/Seq/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Seq.mlg" 3 | ((((def 4 | executeWhenLoaded 5 | (seq 6 | (let #Seq.x_0 (apply Int32# (int32 1))) 7 | (let #Seq.y_1 (apply Int32# (int32 2))) 8 | (do 9 | (apply 10 | printString 11 | (parens 12 | (apply 13 | toStringInt32 14 | (parens (apply (apply addInt32 #Seq.x_0) #Seq.y_1)))))) 15 | (do (apply (apply addInt32 #Seq.x_0) #Seq.y_1))))) 16 | ((def 17 | main 18 | (fn 19 | ((clause 20 | (#Seq.__2) 21 | (seq 22 | (do 23 | (apply 24 | printString 25 | (parens (apply toStringInt32 executeWhenLoaded))))))))))) 26 | () 27 | () 28 | () 29 | () 30 | ((import "runtime/malgo/Builtin.mlg" all) 31 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/TestList/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/TestList.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#TestList.__0) 8 | (seq 9 | (let 10 | #TestList.xs_1 11 | (apply 12 | (apply Cons (apply Int32# (int32 1))) 13 | (apply 14 | (apply Cons (apply Int32# (int32 2))) 15 | (apply (apply Cons (apply Int32# (int32 3))) Nil)))) 16 | (let #TestList.nil_2 Nil) 17 | (do 18 | (apply 19 | putStrLn 20 | (parens 21 | (apply 22 | toStringInt32 23 | (parens (apply head #TestList.xs_1))))))))))))) 24 | () 25 | () 26 | () 27 | () 28 | ((import "runtime/malgo/Builtin.mlg" all) 29 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/TestList/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/TestList.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#TestList.__0) 8 | (seq 9 | (let 10 | #TestList.xs_1 11 | (apply 12 | (apply Cons (apply Int32# (int32 1))) 13 | (apply 14 | (apply Cons (apply Int32# (int32 2))) 15 | (apply (apply Cons (apply Int32# (int32 3))) Nil)))) 16 | (let #TestList.nil_2 Nil) 17 | (do 18 | (apply 19 | putStrLn 20 | (parens 21 | (apply 22 | toStringInt32 23 | (parens (apply head #TestList.xs_1))))))))))))) 24 | () 25 | () 26 | () 27 | () 28 | ((import "runtime/malgo/Builtin.mlg" all) 29 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/Test2/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Test2.mlg" 3 | ((data RGB () ((R ()) (G ()) (B ()))) 4 | (def rtob (fn ((clause (R) (seq (do B))) (clause (a) (seq (do a)))))) 5 | (foreign malgo_print_string (-> String# (tuple))) 6 | (def 7 | main 8 | (fn 9 | ((clause 10 | (_) 11 | (seq 12 | (do 13 | (apply 14 | (fn 15 | ((clause 16 | (B) 17 | (seq 18 | (do (apply malgo_print_string (string "OK"))))) 19 | (clause 20 | (_) 21 | (seq 22 | (do 23 | (apply 24 | malgo_print_string 25 | (string "WRONG"))))))) 26 | (parens (apply rtob R))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Parser/Test2/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/Test2.mlg" 3 | ((data RGB () ((R ()) (G ()) (B ()))) 4 | (def rtob (fn ((clause (R) (seq (do B))) (clause (a) (seq (do a)))))) 5 | (foreign malgo_print_string (-> String# (tuple))) 6 | (def 7 | main 8 | (fn 9 | ((clause 10 | (_) 11 | (seq 12 | (do 13 | (apply 14 | (fn 15 | ((clause 16 | (B) 17 | (seq 18 | (do (apply malgo_print_string (string "OK"))))) 19 | (clause 20 | (_) 21 | (seq 22 | (do 23 | (apply 24 | malgo_print_string 25 | (string "WRONG"))))))) 26 | (parens (apply rtob R))))))))))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/HelloImport/sexpr/actual: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/HelloImport.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#HelloImport.__0) 8 | (seq 9 | (do (apply putStr (parens (apply String# (string "hello"))))) 10 | (do 11 | (opapp 12 | |> 13 | putStrLn 14 | (fn 15 | ((clause 16 | (#HelloImport.f_1) 17 | (seq 18 | (do 19 | (apply 20 | #HelloImport.f_1 21 | (parens 22 | (apply String# (string " world")))))))))))))))))) 23 | ((sig main (-> (tuple) (tuple)))) 24 | () 25 | () 26 | () 27 | ((import "runtime/malgo/Builtin.mlg" all) 28 | (import "runtime/malgo/Prelude.mlg" all)))) -------------------------------------------------------------------------------- /.golden/Malgo.Rename/HelloImport/sexpr/golden: -------------------------------------------------------------------------------- 1 | (module 2 | "test/testcases/malgo/HelloImport.mlg" 3 | ((((def 4 | main 5 | (fn 6 | ((clause 7 | (#HelloImport.__0) 8 | (seq 9 | (do (apply putStr (parens (apply String# (string "hello"))))) 10 | (do 11 | (opapp 12 | |> 13 | putStrLn 14 | (fn 15 | ((clause 16 | (#HelloImport.f_1) 17 | (seq 18 | (do 19 | (apply 20 | #HelloImport.f_1 21 | (parens 22 | (apply String# (string " world")))))))))))))))))) 23 | ((sig main (-> (tuple) (tuple)))) 24 | () 25 | () 26 | () 27 | ((import "runtime/malgo/Builtin.mlg" all) 28 | (import "runtime/malgo/Prelude.mlg" all)))) --------------------------------------------------------------------------------