├── .github └── workflows │ └── main.yml ├── .gitignore ├── .travis.yml ├── Doxyfile ├── Makefile ├── README.md ├── ccan ├── asprintf │ ├── LICENSE │ ├── _info │ ├── asprintf.c │ └── asprintf.h └── compiler │ ├── LICENSE │ ├── _info │ └── compiler.h ├── config.h ├── ctests └── main.c ├── licenses ├── BSD-MIT └── CC0 ├── mk └── target.mk ├── package-sets ├── mkPackage.dhall └── packages.dhall ├── package.json ├── packages.dhall ├── purec.suppr ├── runtime ├── purescript.c └── purescript.h ├── scripts └── bower-depgraph ├── spago.dhall ├── src ├── Language │ └── PureScript │ │ ├── CodeGen │ │ ├── C.purs │ │ ├── C │ │ │ ├── AST.purs │ │ │ ├── AST │ │ │ │ └── Common.purs │ │ │ ├── Common.purs │ │ │ ├── Constants.purs │ │ │ ├── File.purs │ │ │ ├── Optimizer.purs │ │ │ ├── Optimizer │ │ │ │ ├── Blocks.purs │ │ │ │ ├── Common.purs │ │ │ │ ├── Inliner.purs │ │ │ │ ├── MagicDo.purs │ │ │ │ ├── TCO.purs │ │ │ │ └── Unused.purs │ │ │ ├── Pretty.purs │ │ │ ├── Printer.purs │ │ │ ├── Transforms.purs │ │ │ ├── Traversals.purs │ │ │ └── Types.purs │ │ ├── Common.purs │ │ ├── CompileError.purs │ │ ├── Runtime.purs │ │ └── SupplyT.purs │ │ └── Constants.purs ├── Main.js └── Main.purs ├── test ├── Main.purs ├── Upstream.purs ├── Utils.js └── Utils.purs ├── tests ├── 00-basic │ ├── .gitignore │ ├── Makefile │ ├── packages.dhall │ ├── spago.dhall │ └── src │ │ └── Main.purs ├── 01-partialfuns │ ├── .gitignore │ ├── Makefile │ ├── packages.dhall │ ├── spago.dhall │ └── src │ │ └── Main.purs ├── 02-foreign │ ├── .gitignore │ ├── Makefile │ ├── packages.dhall │ ├── spago.dhall │ └── src │ │ ├── Main.c │ │ ├── Main.h │ │ └── Main.purs ├── 03-mutrec │ ├── .gitignore │ ├── Makefile │ ├── packages.dhall │ ├── spago.dhall │ └── src │ │ └── Main.purs ├── 04-memory │ ├── .gitignore │ ├── Makefile │ ├── packages.dhall │ ├── spago.dhall │ └── src │ │ ├── Main.c │ │ ├── Main.h │ │ └── Main.purs ├── 05-datacons │ ├── .gitignore │ ├── Makefile │ ├── packages.dhall │ ├── spago.dhall │ └── src │ │ └── Main.purs ├── 06-typeclasses │ ├── .gitignore │ ├── Makefile │ ├── packages.dhall │ ├── spago.dhall │ └── src │ │ └── Main.purs ├── 10-prelude │ ├── Makefile │ ├── spago.dhall │ └── src │ │ ├── Main.h │ │ └── Main.purs ├── 11-effects │ ├── Makefile │ ├── spago.dhall │ └── src │ │ ├── Main.h │ │ └── Main.purs ├── 12-rec-fns │ ├── Makefile │ ├── spago.dhall │ └── src │ │ └── Main.purs └── main.stub.c ├── upstream └── tests │ ├── purs │ └── passing │ │ ├── 2018 │ │ ├── A.purs │ │ └── B.purs │ │ ├── 2138 │ │ └── Lib.purs │ │ ├── 2609 │ │ └── Eg.purs │ │ ├── 3114 │ │ └── VendoredVariant.purs │ │ ├── 1110.purs │ │ ├── 1185.purs │ │ ├── 1335.purs │ │ ├── 1570.purs │ │ ├── 1664.purs │ │ ├── 1697.purs │ │ ├── 1807.purs │ │ ├── 1881.purs │ │ ├── 1991.purs │ │ ├── 2018.purs │ │ ├── 2049.purs │ │ ├── 2136.purs │ │ ├── 2138.purs │ │ ├── 2172.c │ │ ├── 2172.h │ │ ├── 2172.js │ │ ├── 2172.purs │ │ ├── 2197-1.purs │ │ ├── 2197-2.purs │ │ ├── 2252.purs │ │ ├── 2288.purs │ │ ├── 2378.purs │ │ ├── 2438.purs │ │ ├── 2609.purs │ │ ├── 2616.purs │ │ ├── 2626.purs │ │ ├── 2663.purs │ │ ├── 2689.purs │ │ ├── 2756.purs │ │ ├── 2787.purs │ │ ├── 2795.purs │ │ ├── 2803.purs │ │ ├── 2806.purs │ │ ├── 2947.purs │ │ ├── 2958.purs │ │ ├── 2972.purs │ │ ├── 3114.purs │ │ ├── 3125.purs │ │ ├── 3187-UnusedNameClash.purs │ │ ├── 652.purs │ │ ├── 810.purs │ │ ├── 862.purs │ │ ├── 922.purs │ │ ├── Ado.purs │ │ ├── AppendInReverse.purs │ │ ├── Applicative.purs │ │ ├── ArrayType.purs │ │ ├── Auto.purs │ │ ├── AutoPrelude.purs │ │ ├── AutoPrelude2.purs │ │ ├── BindersInFunctions.purs │ │ ├── BindingGroups.purs │ │ ├── BlockString.purs │ │ ├── CaseInDo.purs │ │ ├── CaseInputWildcard.purs │ │ ├── CaseMultipleExpressions.purs │ │ ├── CaseStatement.purs │ │ ├── CheckFunction.purs │ │ ├── CheckSynonymBug.purs │ │ ├── CheckTypeClass.purs │ │ ├── Church.purs │ │ ├── ClassRefSyntax.purs │ │ ├── ClassRefSyntax │ │ └── Lib.purs │ │ ├── Collatz.purs │ │ ├── Comparisons.purs │ │ ├── Conditional.purs │ │ ├── Console.purs │ │ ├── ConstraintInference.purs │ │ ├── ConstraintParens.purs │ │ ├── ConstraintParsingIssue.purs │ │ ├── ContextSimplification.purs │ │ ├── DataAndType.purs │ │ ├── DataConsClassConsOverlapOk.purs │ │ ├── DctorName.purs │ │ ├── DctorOperatorAlias.purs │ │ ├── DctorOperatorAlias │ │ └── List.purs │ │ ├── DeepArrayBinder.purs │ │ ├── DeepCase.purs │ │ ├── DeriveNewtype.purs │ │ ├── DeriveWithNestedSynonyms.purs │ │ ├── Deriving.purs │ │ ├── DerivingFunctor.purs │ │ ├── Do.purs │ │ ├── Dollar.purs │ │ ├── DuplicateProperties.purs │ │ ├── EffFn.c │ │ ├── EffFn.h │ │ ├── EffFn.js │ │ ├── EffFn.purs │ │ ├── EmptyDataDecls.purs │ │ ├── EmptyRow.purs │ │ ├── EmptyTypeClass.purs │ │ ├── EntailsKindedType.purs │ │ ├── Eq1Deriving.purs │ │ ├── Eq1InEqDeriving.purs │ │ ├── EqOrd.purs │ │ ├── ExplicitImportReExport.purs │ │ ├── ExplicitImportReExport │ │ ├── Bar.purs │ │ └── Foo.purs │ │ ├── ExplicitOperatorSections.purs │ │ ├── ExportExplicit.purs │ │ ├── ExportExplicit │ │ └── M1.purs │ │ ├── ExportExplicit2.purs │ │ ├── ExportExplicit2 │ │ └── M1.purs │ │ ├── ExportedInstanceDeclarations.purs │ │ ├── ExtendedInfixOperators.purs │ │ ├── Fib.purs │ │ ├── FieldConsPuns.purs │ │ ├── FieldPuns.purs │ │ ├── FinalTagless.purs │ │ ├── ForeignKind.purs │ │ ├── ForeignKind │ │ └── Lib.purs │ │ ├── FunWithFunDeps.c │ │ ├── FunWithFunDeps.h │ │ ├── FunWithFunDeps.js │ │ ├── FunWithFunDeps.purs │ │ ├── FunctionScope.purs │ │ ├── FunctionalDependencies.purs │ │ ├── Functions.purs │ │ ├── Functions2.purs │ │ ├── Generalization1.purs │ │ ├── GenericsRep.purs │ │ ├── Guards.purs │ │ ├── HasOwnProperty.purs │ │ ├── HoistError.purs │ │ ├── IfThenElseMaybe.purs │ │ ├── IfWildcard.purs │ │ ├── ImplicitEmptyImport.purs │ │ ├── ImportExplicit.purs │ │ ├── ImportExplicit │ │ └── M1.purs │ │ ├── ImportHiding.purs │ │ ├── ImportQualified.purs │ │ ├── ImportQualified │ │ └── M1.purs │ │ ├── InferRecFunWithConstrainedArgument.purs │ │ ├── InstanceBeforeClass.purs │ │ ├── InstanceChain.purs │ │ ├── InstanceSigs.purs │ │ ├── InstanceSigsGeneral.purs │ │ ├── IntAndChar.purs │ │ ├── JSReserved.purs │ │ ├── KindedType.purs │ │ ├── LargeSumType.purs │ │ ├── Let.purs │ │ ├── Let2.purs │ │ ├── LetInInstance.purs │ │ ├── LetPattern.purs │ │ ├── LiberalTypeSynonyms.purs │ │ ├── MPTCs.purs │ │ ├── Match.purs │ │ ├── Module.purs │ │ ├── Module │ │ ├── M1.purs │ │ └── M2.purs │ │ ├── ModuleDeps.purs │ │ ├── ModuleDeps │ │ ├── M1.purs │ │ ├── M2.purs │ │ └── M3.purs │ │ ├── ModuleExport.purs │ │ ├── ModuleExport │ │ └── A.purs │ │ ├── ModuleExportDupes.purs │ │ ├── ModuleExportDupes │ │ ├── A.purs │ │ ├── B.purs │ │ └── C.purs │ │ ├── ModuleExportExcluded.purs │ │ ├── ModuleExportExcluded │ │ └── A.purs │ │ ├── ModuleExportQualified.purs │ │ ├── ModuleExportQualified │ │ └── A.purs │ │ ├── ModuleExportSelf.purs │ │ ├── ModuleExportSelf │ │ └── A.purs │ │ ├── Monad.purs │ │ ├── MonadState.purs │ │ ├── MultiArgFunctions.purs │ │ ├── MutRec.purs │ │ ├── MutRec2.purs │ │ ├── MutRec3.purs │ │ ├── NakedConstraint.purs │ │ ├── NamedPatterns.purs │ │ ├── NegativeBinder.purs │ │ ├── NegativeIntInRange.purs │ │ ├── Nested.purs │ │ ├── NestedRecordUpdate.purs │ │ ├── NestedRecordUpdateWildcards.purs │ │ ├── NestedTypeSynonyms.purs │ │ ├── NestedWhere.purs │ │ ├── NewConsClass.purs │ │ ├── Newtype.purs │ │ ├── NewtypeClass.purs │ │ ├── NewtypeEff.purs │ │ ├── NewtypeInstance.purs │ │ ├── NewtypeWithRecordUpdate.purs │ │ ├── NonConflictingExports.purs │ │ ├── NonConflictingExports │ │ └── A.purs │ │ ├── NonOrphanInstanceFunDepExtra.purs │ │ ├── NonOrphanInstanceFunDepExtra │ │ └── Lib.purs │ │ ├── NonOrphanInstanceMulti.purs │ │ ├── NonOrphanInstanceMulti │ │ └── Lib.purs │ │ ├── NumberLiterals.purs │ │ ├── ObjectGetter.purs │ │ ├── ObjectSynonym.purs │ │ ├── ObjectUpdate.purs │ │ ├── ObjectUpdate2.purs │ │ ├── ObjectUpdater.purs │ │ ├── ObjectWildcards.purs │ │ ├── Objects.purs │ │ ├── OneConstructor.purs │ │ ├── OperatorAlias.purs │ │ ├── OperatorAliasElsewhere.purs │ │ ├── OperatorAliasElsewhere │ │ └── Def.purs │ │ ├── OperatorAssociativity.purs │ │ ├── OperatorInlining.purs │ │ ├── OperatorSections.purs │ │ ├── Operators.purs │ │ ├── Operators │ │ └── Other.purs │ │ ├── OptimizerBug.purs │ │ ├── OptionalQualified.purs │ │ ├── Ord1Deriving.purs │ │ ├── Ord1InOrdDeriving.purs │ │ ├── ParensInType.purs │ │ ├── ParensInTypedBinder.purs │ │ ├── PartialFunction.purs │ │ ├── Patterns.purs │ │ ├── PendingConflictingImports.purs │ │ ├── PendingConflictingImports │ │ ├── A.purs │ │ └── B.purs │ │ ├── PendingConflictingImports2.purs │ │ ├── PendingConflictingImports2 │ │ └── A.purs │ │ ├── Person.purs │ │ ├── PolyLabels.c │ │ ├── PolyLabels.h │ │ ├── PolyLabels.js │ │ ├── PolyLabels.purs │ │ ├── PrimedTypeName.purs │ │ ├── QualifiedNames.purs │ │ ├── QualifiedNames │ │ └── Either.purs │ │ ├── QualifiedQualifiedImports.purs │ │ ├── Rank2Object.purs │ │ ├── Rank2TypeSynonym.purs │ │ ├── Rank2Types.purs │ │ ├── ReExportQualified.purs │ │ ├── ReExportQualified │ │ ├── A.purs │ │ ├── B.purs │ │ └── C.purs │ │ ├── RebindableSyntax.purs │ │ ├── Recursion.purs │ │ ├── RedefinedFixity.purs │ │ ├── RedefinedFixity │ │ ├── M1.purs │ │ ├── M2.purs │ │ └── M3.purs │ │ ├── ReservedWords.purs │ │ ├── ResolvableScopeConflict.purs │ │ ├── ResolvableScopeConflict │ │ ├── A.purs │ │ └── B.purs │ │ ├── ResolvableScopeConflict2.purs │ │ ├── ResolvableScopeConflict2 │ │ └── A.purs │ │ ├── ResolvableScopeConflict3.purs │ │ ├── ResolvableScopeConflict3 │ │ └── A.purs │ │ ├── RowConstructors.purs │ │ ├── RowInInstanceHeadDetermined.purs │ │ ├── RowLacks.purs │ │ ├── RowNub.purs │ │ ├── RowPolyInstanceContext.purs │ │ ├── RowUnion.c │ │ ├── RowUnion.h │ │ ├── RowUnion.js │ │ ├── RowUnion.purs │ │ ├── RowsInInstanceContext.purs │ │ ├── RunFnInline.purs │ │ ├── RuntimeScopeIssue.purs │ │ ├── ScopedTypeVariables.purs │ │ ├── Sequence.purs │ │ ├── SequenceDesugared.purs │ │ ├── ShadowedModuleName.purs │ │ ├── ShadowedModuleName │ │ └── Test.purs │ │ ├── ShadowedName.purs │ │ ├── ShadowedRename.purs │ │ ├── ShadowedTCO.purs │ │ ├── ShadowedTCOLet.purs │ │ ├── SignedNumericLiterals.purs │ │ ├── SolvingAppendSymbol.purs │ │ ├── SolvingCompareSymbol.purs │ │ ├── SolvingIsSymbol.purs │ │ ├── SolvingIsSymbol │ │ └── Lib.purs │ │ ├── Stream.purs │ │ ├── StringEdgeCases.purs │ │ ├── StringEdgeCases │ │ ├── Records.purs │ │ └── Symbols.purs │ │ ├── StringEscapes.purs │ │ ├── Superclasses1.purs │ │ ├── Superclasses3.purs │ │ ├── TCO.purs │ │ ├── TCOCase.purs │ │ ├── TailCall.purs │ │ ├── Tick.purs │ │ ├── TopLevelCase.purs │ │ ├── TransitiveImport.purs │ │ ├── TransitiveImport │ │ ├── Middle.purs │ │ └── Test.purs │ │ ├── TypeClassMemberOrderChange.purs │ │ ├── TypeClasses.purs │ │ ├── TypeClassesInOrder.purs │ │ ├── TypeClassesWithOverlappingTypeVariables.purs │ │ ├── TypeDecl.purs │ │ ├── TypeOperators.purs │ │ ├── TypeOperators │ │ └── A.purs │ │ ├── TypeSynonymInData.purs │ │ ├── TypeSynonyms.purs │ │ ├── TypeWildcards.purs │ │ ├── TypeWildcardsRecordExtension.purs │ │ ├── TypeWithoutParens.purs │ │ ├── TypeWithoutParens │ │ └── Lib.purs │ │ ├── TypedBinders.purs │ │ ├── TypedWhere.purs │ │ ├── UTF8Sourcefile.purs │ │ ├── UnderscoreIdent.purs │ │ ├── UnicodeIdentifier.purs │ │ ├── UnicodeOperators.purs │ │ ├── UnicodeType.purs │ │ ├── UnifyInTypeInstanceLookup.purs │ │ ├── Unit.purs │ │ ├── UnknownInTypeClassLookup.purs │ │ ├── UnsafeCoerce.purs │ │ ├── UntupledConstraints.purs │ │ ├── UsableTypeClassMethods.purs │ │ ├── Where.purs │ │ ├── WildcardInInstance.purs │ │ ├── WildcardType.purs │ │ ├── iota.purs │ │ └── s.purs │ └── support │ ├── .gitignore │ └── spago.dhall └── vendor ├── asprintf.h ├── utf8.h ├── uthash.h ├── vec.c └── vec.h /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ master, next, perf, ci ] 6 | pull_request: 7 | branches: [ master, next ] 8 | workflow_dispatch: 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v2 15 | - uses: actions/setup-node@v2.1.4 16 | - run: sudo apt install -y valgrind libcmocka-dev 17 | - run: npm install 18 | - run: npm run build 19 | - run: npm test 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .spago 2 | .spago.sources.sum 3 | /html/ 4 | /latex/ 5 | .psc-package/ 6 | *.out 7 | *.tar.bz2 8 | *.gch 9 | *.o 10 | *.a 11 | *.tar.gz 12 | *.tmp 13 | *.zip 14 | bower_components/ 15 | node_modules/ 16 | output/ 17 | deps/ 18 | .output/ 19 | .purec-work/ 20 | purec.js -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | os: 3 | - linux 4 | - osx 5 | dist: trusty 6 | sudo: required 7 | node_js: stable 8 | install: 9 | - make deps 10 | env: 11 | global: 12 | - PATH=node_modules/.bin:$PATH 13 | script: 14 | - make purec 15 | - make test 16 | -------------------------------------------------------------------------------- /ccan/asprintf/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/BSD-MIT -------------------------------------------------------------------------------- /ccan/asprintf/_info: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * asprintf - asprintf wrapper (and if necessary, implementation). 7 | * 8 | * This provides a convenient wrapper for asprintf, and also implements 9 | * asprintf if necessary. 10 | * 11 | * Author: Rusty Russell 12 | * 13 | * License: MIT 14 | * 15 | * Example: 16 | * #include 17 | * #include 18 | * #include 19 | * 20 | * int main(int argc, char *argv[]) 21 | * { 22 | * char *p = afmt("This program has %i arguments", argc); 23 | * int ret; 24 | * 25 | * while ((ret = write(STDOUT_FILENO, p, strlen(p))) > 0) { 26 | * p += ret; 27 | * if (!*p) 28 | * exit(0); 29 | * } 30 | * err(1, "Writing to stdout"); 31 | * } 32 | */ 33 | int main(int argc, char *argv[]) 34 | { 35 | /* Expect exactly one argument */ 36 | if (argc != 2) 37 | return 1; 38 | 39 | if (strcmp(argv[1], "depends") == 0) { 40 | printf("ccan/compiler\n"); 41 | return 0; 42 | } 43 | 44 | return 1; 45 | } 46 | -------------------------------------------------------------------------------- /ccan/asprintf/asprintf.c: -------------------------------------------------------------------------------- 1 | /* Licensed under BSD-MIT - see LICENSE file for details */ 2 | #include 3 | #include 4 | #include 5 | 6 | char *PRINTF_FMT(1, 2) afmt(const char *fmt, ...) 7 | { 8 | va_list ap; 9 | char *ptr; 10 | 11 | va_start(ap, fmt); 12 | /* The BSD version apparently sets ptr to NULL on fail. GNU loses. */ 13 | if (vasprintf(&ptr, fmt, ap) < 0) 14 | ptr = NULL; 15 | va_end(ap); 16 | return ptr; 17 | } 18 | 19 | #if !HAVE_ASPRINTF 20 | #include 21 | #include 22 | 23 | int vasprintf(char **strp, const char *fmt, va_list ap) 24 | { 25 | int len; 26 | va_list ap_copy; 27 | 28 | /* We need to make a copy of ap, since it's a use-once. */ 29 | va_copy(ap_copy, ap); 30 | len = vsnprintf(NULL, 0, fmt, ap_copy); 31 | va_end(ap_copy); 32 | 33 | /* Until version 2.0.6 glibc would return -1 on truncated output. 34 | * OTOH, they had asprintf. */ 35 | if (len < 0) 36 | return -1; 37 | 38 | *strp = malloc(len+1); 39 | if (!*strp) 40 | return -1; 41 | 42 | return vsprintf(*strp, fmt, ap); 43 | } 44 | 45 | int asprintf(char **strp, const char *fmt, ...) 46 | { 47 | va_list ap; 48 | int len; 49 | 50 | va_start(ap, fmt); 51 | len = vasprintf(strp, fmt, ap); 52 | va_end(ap); 53 | 54 | return len; 55 | } 56 | #endif /* !HAVE_ASPRINTF */ 57 | -------------------------------------------------------------------------------- /ccan/asprintf/asprintf.h: -------------------------------------------------------------------------------- 1 | /* Licensed under BSD-MIT - see LICENSE file for details */ 2 | #ifndef CCAN_ASPRINTF_H 3 | #define CCAN_ASPRINTF_H 4 | #include "config.h" 5 | #include 6 | 7 | /** 8 | * afmt - allocate and populate a string with the given format. 9 | * @fmt: printf-style format. 10 | * 11 | * This is a simplified asprintf interface. Returns NULL on error. 12 | */ 13 | char *PRINTF_FMT(1, 2) afmt(const char *fmt, ...); 14 | 15 | #if HAVE_ASPRINTF 16 | #include 17 | #else 18 | #include 19 | /** 20 | * asprintf - printf to a dynamically-allocated string. 21 | * @strp: pointer to the string to allocate. 22 | * @fmt: printf-style format. 23 | * 24 | * Returns -1 (and leaves @strp undefined) on an error. Otherwise returns 25 | * number of bytes printed into @strp. 26 | * 27 | * Example: 28 | * static char *greeting(const char *name) 29 | * { 30 | * char *str; 31 | * int len = asprintf(&str, "Hello %s", name); 32 | * if (len < 0) 33 | * return NULL; 34 | * return str; 35 | * } 36 | */ 37 | int PRINTF_FMT(2, 3) asprintf(char **strp, const char *fmt, ...); 38 | 39 | /** 40 | * vasprintf - vprintf to a dynamically-allocated string. 41 | * @strp: pointer to the string to allocate. 42 | * @fmt: printf-style format. 43 | * 44 | * Returns -1 (and leaves @strp undefined) on an error. Otherwise returns 45 | * number of bytes printed into @strp. 46 | */ 47 | int vasprintf(char **strp, const char *fmt, va_list ap); 48 | #endif 49 | 50 | #endif /* CCAN_ASPRINTF_H */ 51 | -------------------------------------------------------------------------------- /ccan/compiler/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /config.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pure-c/purec/1b7ff43cc011efd4ebb44cfa389e16a7ca954c60/config.h -------------------------------------------------------------------------------- /licenses/BSD-MIT: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy 2 | of this software and associated documentation files (the "Software"), to deal 3 | in the Software without restriction, including without limitation the rights 4 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 5 | copies of the Software, and to permit persons to whom the Software is 6 | furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in 9 | all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 17 | THE SOFTWARE. 18 | -------------------------------------------------------------------------------- /package-sets/mkPackage.dhall: -------------------------------------------------------------------------------- 1 | let mkPackage = 2 | https://raw.githubusercontent.com/purescript/package-sets/psc-0.12.5/src/mkPackage.dhall sha256:0b197efa1d397ace6eb46b243ff2d73a3da5638d8d0ac8473e8e4a8fc528cf57 3 | 4 | in mkPackage 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pure-c", 3 | "version": "0.0.0", 4 | "description": "A C backend for PureScript", 5 | "main": "index.js", 6 | "bin": { 7 | "purec": "purec.js" 8 | }, 9 | "directories": { 10 | "example": "examples", 11 | "test": "test" 12 | }, 13 | "dependencies": { 14 | "posix-getopt": "^1.2.0" 15 | }, 16 | "devDependencies": { 17 | "bower": "^1.8.4", 18 | "pulp": "^12.3.0", 19 | "purescript": "^0.13.2", 20 | "spago": "^0.17.0" 21 | }, 22 | "scripts": { 23 | "test": "make check", 24 | "build": "spago bundle-app -t purec.js", 25 | "watch": "spago bundle-app -w -t purec.js", 26 | "docs": "doxygen Doxyfile" 27 | }, 28 | "repository": { 29 | "type": "git", 30 | "url": "git+https://github.com/pure-c/pure-c.git" 31 | }, 32 | "keywords": [ 33 | "PureScript", 34 | "C", 35 | "backend" 36 | ], 37 | "author": "Felix Schlitter ", 38 | "license": "MIT", 39 | "bugs": { 40 | "url": "https://github.com/pure-c/pure-c/issues" 41 | }, 42 | "homepage": "https://github.com/pure-c/pure-c#readme" 43 | } 44 | -------------------------------------------------------------------------------- /packages.dhall: -------------------------------------------------------------------------------- 1 | let mkPackage = 2 | https://raw.githubusercontent.com/purescript/package-sets/psc-0.13.2/src/mkPackage.dhall sha256:0b197efa1d397ace6eb46b243ff2d73a3da5638d8d0ac8473e8e4a8fc528cf57 3 | 4 | let upstream = 5 | https://raw.githubusercontent.com/purescript/package-sets/psc-0.13.2/src/packages.dhall sha256:906af79ba3aec7f429b107fd8d12e8a29426db8229d228c6f992b58151e2308e 6 | 7 | let overrides = 8 | { foreign = 9 | upstream.foreign 10 | // { version = "ad52524676eb2243974010ceebe2cde7a8b8bea7" } 11 | } 12 | 13 | let additions = 14 | { corefn = 15 | mkPackage 16 | [ "console" 17 | , "foreign-generic" 18 | , "errors" 19 | , "strings" 20 | , "newtype" 21 | , "tuples" 22 | , "foldable-traversable" 23 | , "profunctor" 24 | , "aff" 25 | ] 26 | "https://github.com/felixschl/purescript-corefn.git" 27 | "eee6e976e97765966eceb34d085a80438f32cdb2" 28 | } 29 | 30 | in upstream // overrides // additions 31 | -------------------------------------------------------------------------------- /purec.suppr: -------------------------------------------------------------------------------- 1 | { 2 | 3 | Memcheck:Cond 4 | ... 5 | fun:GC_* 6 | } 7 | 8 | { 9 | 10 | Memcheck:Value8 11 | ... 12 | fun:GC_* 13 | } 14 | 15 | { 16 | 17 | Memcheck:Leak 18 | ... 19 | fun:GC_* 20 | } 21 | 22 | { 23 | 24 | Memcheck:Addr8 25 | ... 26 | fun:GC_* 27 | } 28 | 29 | { 30 | 31 | Memcheck:Cond 32 | ... 33 | fun:*$__thunk_fn__init 34 | ... 35 | } 36 | 37 | { 38 | 39 | Memcheck:Value8 40 | ... 41 | fun:*$__thunk_fn__init 42 | ... 43 | } 44 | 45 | { 46 | 47 | Memcheck:Leak 48 | ... 49 | fun:*$__thunk_fn__init 50 | ... 51 | } 52 | 53 | { 54 | 55 | Memcheck:Addr8 56 | ... 57 | fun:*$__thunk_fn__init 58 | ... 59 | } 60 | -------------------------------------------------------------------------------- /spago.dhall: -------------------------------------------------------------------------------- 1 | { name = "purec" 2 | , dependencies = 3 | [ "aff" 4 | , "avar" 5 | , "node-fs-aff" 6 | , "node-streams" 7 | , "corefn" 8 | , "spec" 9 | , "argonaut" 10 | , "nullable" 11 | , "console" 12 | , "effect" 13 | , "prelude" 14 | , "free" 15 | , "psci-support" 16 | , "debug" 17 | , "node-process" 18 | , "node-child-process" 19 | , "foreign" 20 | , "node-readline" 21 | , "optparse" 22 | ] 23 | , packages = ./packages.dhall 24 | , sources = [ "src/**/*.purs", "test/**/*.purs" ] 25 | } 26 | -------------------------------------------------------------------------------- /src/Language/PureScript/CodeGen/C/AST/Common.purs: -------------------------------------------------------------------------------- 1 | module Language.PureScript.CodeGen.C.AST.Common 2 | ( isReferenced 3 | ) where 4 | 5 | import Prelude 6 | 7 | import Language.PureScript.CodeGen.C.AST (AST) 8 | import Language.PureScript.CodeGen.C.AST as AST 9 | 10 | data IsUsed 11 | = Used 12 | | Shadowed 13 | | Unused 14 | 15 | derive instance eqIsUsed :: Eq IsUsed 16 | 17 | combine :: IsUsed -> IsUsed -> IsUsed 18 | combine Used _ = Used 19 | combine Unused x = x 20 | combine Shadowed _ = Shadowed 21 | 22 | isReferenced :: String -> AST -> Boolean 23 | isReferenced needle ast = 24 | AST.everything combine go ast == Used 25 | where 26 | go (AST.VariableIntroduction { name }) | name == needle = Shadowed 27 | go (AST.Assignment (AST.Var name) _) | name == needle = Shadowed 28 | go (AST.Var name) | name == needle = Used 29 | go _ = Unused 30 | -------------------------------------------------------------------------------- /src/Language/PureScript/CodeGen/C/Constants.purs: -------------------------------------------------------------------------------- 1 | module Language.PureScript.CodeGen.C.Constants 2 | ( __unused 3 | ) where 4 | 5 | import Language.PureScript.CodeGen.C.AST (AST) 6 | import Language.PureScript.CodeGen.C.AST as AST 7 | 8 | __unused :: String 9 | __unused = "__unused" 10 | -------------------------------------------------------------------------------- /src/Language/PureScript/CodeGen/C/Optimizer/Blocks.purs: -------------------------------------------------------------------------------- 1 | module Language.PureScript.CodeGen.C.Optimizer.Blocks 2 | ( collapseNestedBlocks 3 | , collapseNestedIfs 4 | ) where 5 | 6 | import Prelude 7 | 8 | import Data.Array as A 9 | import Data.Either (Either(..)) 10 | import Data.Maybe (Maybe(..)) 11 | import Language.PureScript.CodeGen.C.AST (AST) 12 | import Language.PureScript.CodeGen.C.AST as AST 13 | 14 | -- | Collapse blocks which appear nested directly below another block 15 | collapseNestedBlocks :: AST -> AST 16 | collapseNestedBlocks = AST.everywhere collapse 17 | where 18 | collapse :: AST -> AST 19 | collapse (AST.Block sts) = AST.Block (A.concat $ map go sts) 20 | collapse x = x 21 | 22 | go :: AST -> Array AST 23 | go (AST.Block sts) = sts 24 | go s = [s] 25 | 26 | collapseNestedIfs :: AST -> AST 27 | collapseNestedIfs = AST.everywhere collapse 28 | where 29 | collapse :: AST -> AST 30 | collapse (AST.IfElse (AST.NumericLiteral (Left 1)) (AST.Block [ast]) _) = ast 31 | collapse (AST.IfElse cond1 (AST.Block [AST.IfElse cond2 body Nothing]) Nothing) = 32 | AST.IfElse (AST.Binary AST.And cond1 cond2) body Nothing 33 | collapse x = x 34 | -------------------------------------------------------------------------------- /src/Language/PureScript/CodeGen/C/Optimizer/Unused.purs: -------------------------------------------------------------------------------- 1 | module Language.PureScript.CodeGen.C.Optimizer.Unused 2 | ( removeCodeAfterReturnStatements 3 | , removeUndefinedApp 4 | ) where 5 | 6 | import Prelude 7 | 8 | import Data.Array as A 9 | import Data.Maybe (fromMaybe) 10 | import Language.PureScript.Constants as Constants 11 | import Language.PureScript.CodeGen.C.AST (AST, everywhere) 12 | import Language.PureScript.CodeGen.C.AST as AST 13 | import Language.PureScript.CodeGen.C.Optimizer.Common (mapBlock) 14 | 15 | removeCodeAfterReturnStatements :: AST -> AST 16 | removeCodeAfterReturnStatements = everywhere (mapBlock go) 17 | where 18 | go :: Array AST -> Array AST 19 | go asts = fromMaybe asts ado 20 | ix <- A.findIndex isReturn asts 21 | in A.take (ix + 1) asts 22 | 23 | isReturn (AST.Return _) = true 24 | isReturn _ = false 25 | 26 | removeUndefinedApp :: AST -> AST 27 | removeUndefinedApp = everywhere convert 28 | where 29 | convert (AST.App fn [AST.Var arg]) 30 | | arg == Constants.undefined = 31 | AST.App fn [] 32 | convert ast = ast 33 | -------------------------------------------------------------------------------- /src/Language/PureScript/CodeGen/C/Printer.purs: -------------------------------------------------------------------------------- 1 | module Language.PureScript.CodeGen.C.Printer 2 | where 3 | 4 | import Prelude 5 | -------------------------------------------------------------------------------- /src/Language/PureScript/CodeGen/C/Traversals.purs: -------------------------------------------------------------------------------- 1 | module Language.PureScript.CodeGen.C.Traversals where 2 | -------------------------------------------------------------------------------- /src/Language/PureScript/CodeGen/C/Types.purs: -------------------------------------------------------------------------------- 1 | module Language.PureScript.CodeGen.C.Types where 2 | -------------------------------------------------------------------------------- /src/Language/PureScript/CodeGen/Common.purs: -------------------------------------------------------------------------------- 1 | module Language.PureScript.CodeGen.Common 2 | ( runModuleName 3 | ) where 4 | 5 | import Prelude 6 | 7 | import CoreFn.Names as C 8 | import Data.Array as A 9 | import Data.Newtype (unwrap) 10 | import Language.PureScript.CodeGen.C.File as C 11 | 12 | runModuleName :: C.ModuleName -> String 13 | runModuleName = C.cModuleName 14 | -------------------------------------------------------------------------------- /src/Language/PureScript/CodeGen/CompileError.purs: -------------------------------------------------------------------------------- 1 | module Language.PureScript.CodeGen.CompileError 2 | ( CompileError(..) 3 | ) where 4 | 5 | data CompileError 6 | = InternalError String 7 | | NotImplementedError String 8 | -------------------------------------------------------------------------------- /src/Main.js: -------------------------------------------------------------------------------- 1 | exports.errorCodeImpl = function(Nothing) { 2 | return function(Just) { 3 | return function(error) { 4 | return error.code 5 | ? Just (error.code) 6 | : Nothing 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/Main.purs: -------------------------------------------------------------------------------- 1 | module Test.Main 2 | ( main 3 | ) where 4 | 5 | import Prelude 6 | 7 | import Data.Maybe (Maybe(..)) 8 | import Data.Newtype (unwrap) 9 | import Data.Time.Duration (Milliseconds(..)) 10 | import Effect (Effect) 11 | import Effect.Aff (launchAff_) 12 | import Effect.Class (liftEffect) 13 | import Node.Process (lookupEnv) as Process 14 | import Test.Spec.Reporter (specReporter) as Spec 15 | import Test.Spec.Runner (defaultConfig, runSpecT) as Spec 16 | import Test.Upstream (buildUpstreamTestSuite) 17 | 18 | main :: Effect Unit 19 | main = launchAff_ do 20 | only <- liftEffect (Process.lookupEnv "only") 21 | upstreamSpec <- buildUpstreamTestSuite only 22 | unwrap $ Spec.runSpecT 23 | (Spec.defaultConfig { timeout = Nothing }) 24 | [ Spec.specReporter ] $ 25 | upstreamSpec 26 | -------------------------------------------------------------------------------- /test/Utils.js: -------------------------------------------------------------------------------- 1 | exports.errorCodeImpl = function(Nothing) { 2 | return function(Just) { 3 | return function(error) { 4 | return error.code 5 | ? Just (error.code) 6 | : Nothing 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/00-basic/.gitignore: -------------------------------------------------------------------------------- 1 | /bower_components/ 2 | /node_modules/ 3 | /.pulp-cache/ 4 | /output/ 5 | /generated-docs/ 6 | /.psc-package/ 7 | /.psc* 8 | /.purs* 9 | /.psa* 10 | /.spago 11 | -------------------------------------------------------------------------------- /tests/00-basic/Makefile: -------------------------------------------------------------------------------- 1 | default: main 2 | .PHONY: default 3 | 4 | PUREC_DIR := ../.. 5 | include $(PUREC_DIR)/mk/target.mk 6 | 7 | $(eval $(call purs_mk_target,main,Main,src)) 8 | -------------------------------------------------------------------------------- /tests/00-basic/packages.dhall: -------------------------------------------------------------------------------- 1 | let mkPackage = ../../package-sets/mkPackage.dhall 2 | 3 | let upstream = ../../package-sets/packages.dhall 4 | 5 | let overrides = {=} 6 | 7 | let additions = {=} 8 | 9 | in upstream ⫽ overrides ⫽ additions 10 | -------------------------------------------------------------------------------- /tests/00-basic/spago.dhall: -------------------------------------------------------------------------------- 1 | { name = 2 | "purec-test-basic" 3 | , dependencies = 4 | [] : List Text 5 | , packages = 6 | ./packages.dhall 7 | , sources = 8 | [ "src/**/*.purs", "test/**/*.purs" ] 9 | } 10 | -------------------------------------------------------------------------------- /tests/00-basic/src/Main.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | data Unit = Unit 4 | type Effect a = Unit -> a 5 | 6 | chain :: Effect Int -> Effect Int -> Effect Int 7 | chain a b = \_ -> 8 | let x = a Unit 9 | in 10 | case x of 11 | 0 -> b Unit 12 | n -> n 13 | 14 | infixl 5 chain as >> 15 | 16 | testString :: Effect Int 17 | testString _ = 18 | let s = "fooBAZ" 19 | in case s of 20 | "fooBAZ" -> 0 21 | _ -> 1 22 | 23 | testRecord :: Effect Int 24 | testRecord _ = 25 | let r = { a: 1, b: 2, c: [0] } 26 | in 27 | case r { c = [5] } of 28 | { a: 1, b: 2, c: [5] } -> 29 | 0 30 | _ -> 31 | 1 32 | 33 | testArray :: Effect Int 34 | testArray _ = 35 | let xs = [ 1, 2, 0, 3 ] 36 | in 37 | case xs of 38 | [_, _, x, _] -> x 39 | _ -> 1 40 | 41 | main :: Effect Int 42 | main = 43 | testArray >> 44 | testRecord >> 45 | testString 46 | -------------------------------------------------------------------------------- /tests/01-partialfuns/.gitignore: -------------------------------------------------------------------------------- 1 | /bower_components/ 2 | /node_modules/ 3 | /.pulp-cache/ 4 | /output/ 5 | /generated-docs/ 6 | /.psc-package/ 7 | /.psc* 8 | /.purs* 9 | /.psa* 10 | /.spago 11 | -------------------------------------------------------------------------------- /tests/01-partialfuns/Makefile: -------------------------------------------------------------------------------- 1 | default: main 2 | .PHONY: default 3 | 4 | PUREC_DIR := ../.. 5 | include $(PUREC_DIR)/mk/target.mk 6 | 7 | $(eval $(call purs_mk_target,main,Main,src)) 8 | -------------------------------------------------------------------------------- /tests/01-partialfuns/packages.dhall: -------------------------------------------------------------------------------- 1 | let mkPackage = ../../package-sets/mkPackage.dhall 2 | 3 | let upstream = ../../package-sets/packages.dhall 4 | 5 | let overrides = {=} 6 | 7 | let additions = {=} 8 | 9 | in upstream ⫽ overrides ⫽ additions 10 | -------------------------------------------------------------------------------- /tests/01-partialfuns/spago.dhall: -------------------------------------------------------------------------------- 1 | { name = 2 | "purec-test-partialfuns" 3 | , dependencies = 4 | [] : List Text 5 | , packages = 6 | ./packages.dhall 7 | , sources = 8 | [ "src/**/*.purs", "test/**/*.purs" ] 9 | } 10 | -------------------------------------------------------------------------------- /tests/01-partialfuns/src/Main.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | data Unit = Unit 4 | type Effect a = Unit -> a 5 | 6 | chain :: Effect Int -> Effect Int -> Effect Int 7 | chain a b = \_ -> 8 | let x = a Unit 9 | in 10 | case x of 11 | 0 -> b Unit 12 | n -> n 13 | 14 | infixl 5 chain as >> 15 | 16 | const :: ∀ a. a -> (∀ b. b -> a) 17 | const x _ = x 18 | 19 | main :: Effect Int 20 | main = 21 | let 22 | f = const [ 0, 1 ] 23 | f' = const [ 2, 3 ] 24 | r = { a: [ f Unit ] } 25 | h = const (\_ -> (r { a = [ f' Unit ] })) 26 | g = h Unit 27 | in (\_ -> 28 | case f 0 of 29 | [ 0, 1 ] -> 0 30 | _ -> 1) 31 | >> (\_ -> 32 | case f 1 of 33 | [ 0, 1 ] -> 0 34 | _ -> 1) 35 | >> (\_ -> 36 | case f 2 of 37 | [ 0, 1 ] -> 0 38 | _ -> 1) 39 | >> (\_ -> 40 | case g 2 of 41 | { a: [ [ 2, 3 ] ] } -> 0 42 | _ -> 1) 43 | >> (\_ -> 44 | case g 3 of 45 | { a: [ [ 2, 3 ] ] } -> 0 46 | _ -> 1) 47 | >> (\_ -> 48 | case r of 49 | { a: [ [ 0, 1 ] ] } -> 0 50 | _ -> 1) 51 | -------------------------------------------------------------------------------- /tests/02-foreign/.gitignore: -------------------------------------------------------------------------------- 1 | /bower_components/ 2 | /node_modules/ 3 | /.pulp-cache/ 4 | /output/ 5 | /generated-docs/ 6 | /.psc-package/ 7 | /.psc* 8 | /.purs* 9 | /.psa* 10 | /.spago 11 | -------------------------------------------------------------------------------- /tests/02-foreign/Makefile: -------------------------------------------------------------------------------- 1 | default: main 2 | .PHONY: default 3 | 4 | PUREC_DIR := ../.. 5 | include $(PUREC_DIR)/mk/target.mk 6 | 7 | $(eval $(call purs_mk_target,main,Main,src)) 8 | -------------------------------------------------------------------------------- /tests/02-foreign/packages.dhall: -------------------------------------------------------------------------------- 1 | let mkPackage = ../../package-sets/mkPackage.dhall 2 | 3 | let upstream = ../../package-sets/packages.dhall 4 | 5 | let overrides = {=} 6 | 7 | let additions = {=} 8 | 9 | in upstream ⫽ overrides ⫽ additions 10 | -------------------------------------------------------------------------------- /tests/02-foreign/spago.dhall: -------------------------------------------------------------------------------- 1 | { name = 2 | "purec-test-foreign" 3 | , dependencies = 4 | [] : List Text 5 | , packages = 6 | ./packages.dhall 7 | , sources = 8 | [ "src/**/*.purs", "test/**/*.purs" ] 9 | } 10 | -------------------------------------------------------------------------------- /tests/02-foreign/src/Main.c: -------------------------------------------------------------------------------- 1 | #include "runtime/purescript.h" 2 | #include "Main.h" 3 | 4 | void buf_free(void* tag, void* data) { 5 | purs_free(tag); 6 | struct buf * buf = data; 7 | purs_free(buf->data); 8 | purs_free(buf); 9 | } 10 | 11 | PURS_FFI_FUNC_1(Main_newBuffer, _) { 12 | struct buf * buf = purs_new(struct buf); 13 | buf->data = NULL; 14 | buf->size = 0; 15 | return purs_any_foreign(purs_foreign_new(NULL, buf, buf_free)); 16 | } 17 | 18 | PURS_FFI_FUNC_2(Main_bufferSize, x, _) { 19 | assert(x.tag == PURS_ANY_TAG_FOREIGN); 20 | struct buf * buf = (struct buf *) x.value.foreign->data; 21 | return purs_any_int(buf->size); 22 | } 23 | 24 | PURS_FFI_FUNC_3(Main_bufferGrow, n_, x, _) { 25 | assert(x.tag == PURS_ANY_TAG_FOREIGN); 26 | int n = purs_any_unsafe_get_int(n_); 27 | struct buf *buf = (struct buf *) x.value.foreign->data; 28 | char *data = purs_malloc(sizeof (char) * (buf->size + n)); 29 | memcpy(data, buf->data, buf->size); 30 | purs_free(buf->data); 31 | buf->size += n; 32 | buf->data = data; 33 | return purs_any_int(buf->size); 34 | } 35 | -------------------------------------------------------------------------------- /tests/02-foreign/src/Main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | #include "runtime/purescript.h" 5 | 6 | struct buf { 7 | char * data; /* heap-allocated buffer */ 8 | int size; 9 | }; 10 | 11 | PURS_FFI_EXPORT(Main_newBuffer); 12 | PURS_FFI_EXPORT(Main_bufferSize); 13 | PURS_FFI_EXPORT(Main_bufferGrow); 14 | 15 | #endif // MAIN_H 16 | -------------------------------------------------------------------------------- /tests/02-foreign/src/Main.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | data Unit = Unit 4 | type Effect a = Unit -> a 5 | 6 | foreign import data Buffer :: Type 7 | foreign import newBuffer :: Effect Buffer 8 | foreign import bufferSize :: Buffer -> Effect Int 9 | foreign import bufferGrow :: Int -> Buffer -> Effect Int 10 | 11 | pureE :: ∀ a. a -> Effect a 12 | pureE n _ = n 13 | 14 | bindE :: ∀ a b. Effect a -> (a -> Effect b) -> Effect b 15 | bindE a f _ = (f (a Unit)) Unit 16 | 17 | infixl 5 bindE as >>= 18 | 19 | main :: Effect Int 20 | main = 21 | newBuffer >>= \buf -> 22 | bufferSize buf >>= case _ of 23 | 0 -> 24 | bufferGrow 20 buf >>= \_ -> 25 | bufferSize buf >>= case _ of 26 | 20 -> 27 | pureE 0 28 | _ -> 29 | pureE 1 30 | _ -> 31 | pureE 1 32 | -------------------------------------------------------------------------------- /tests/03-mutrec/.gitignore: -------------------------------------------------------------------------------- 1 | /bower_components/ 2 | /node_modules/ 3 | /.pulp-cache/ 4 | /output/ 5 | /generated-docs/ 6 | /.psc-package/ 7 | /.psc* 8 | /.purs* 9 | /.psa* 10 | /.spago 11 | -------------------------------------------------------------------------------- /tests/03-mutrec/Makefile: -------------------------------------------------------------------------------- 1 | default: main 2 | .PHONY: default 3 | 4 | export USE_GC := 1 5 | 6 | PUREC_DIR := ../.. 7 | include $(PUREC_DIR)/mk/target.mk 8 | 9 | $(eval $(call purs_mk_target,main,Main,src)) 10 | -------------------------------------------------------------------------------- /tests/03-mutrec/packages.dhall: -------------------------------------------------------------------------------- 1 | let mkPackage = ../../package-sets/mkPackage.dhall 2 | 3 | let upstream = ../../package-sets/packages.dhall 4 | 5 | let overrides = {=} 6 | 7 | let additions = {=} 8 | 9 | in upstream ⫽ overrides ⫽ additions 10 | -------------------------------------------------------------------------------- /tests/03-mutrec/spago.dhall: -------------------------------------------------------------------------------- 1 | { name = 2 | "purec-test-mutrec" 3 | , dependencies = 4 | [] : List Text 5 | , packages = 6 | ./packages.dhall 7 | , sources = 8 | [ "src/**/*.purs", "test/**/*.purs" ] 9 | } 10 | -------------------------------------------------------------------------------- /tests/03-mutrec/src/Main.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | data Unit = Unit 4 | type Effect a = Unit -> a 5 | 6 | main :: Effect Int 7 | main _ = 8 | let 9 | f = 10 | case _ of 11 | [0] -> 12 | g [1] 13 | [1] -> 14 | g [2] 15 | [2] -> 16 | g [3] 17 | [3] -> 18 | [1] -- 'g' should finish! 19 | _ -> 20 | [1] 21 | g = 22 | case _ of 23 | [0] -> 24 | f [1] 25 | [1] -> 26 | f [2] 27 | [2] -> 28 | f [3] 29 | [3] -> 30 | [0] 31 | _ -> 32 | [1] 33 | in case f [0] of 34 | [0] -> 0 35 | _ -> 1 36 | -------------------------------------------------------------------------------- /tests/04-memory/.gitignore: -------------------------------------------------------------------------------- 1 | /bower_components/ 2 | /node_modules/ 3 | /.pulp-cache/ 4 | /output/ 5 | /generated-docs/ 6 | /.psc-package/ 7 | /.psc* 8 | /.purs* 9 | /.psa* 10 | /.spago 11 | -------------------------------------------------------------------------------- /tests/04-memory/Makefile: -------------------------------------------------------------------------------- 1 | default: main 2 | .PHONY: default 3 | 4 | PUREC_DIR := ../.. 5 | include $(PUREC_DIR)/mk/target.mk 6 | 7 | $(eval $(call purs_mk_target,main,Main,src)) 8 | -------------------------------------------------------------------------------- /tests/04-memory/packages.dhall: -------------------------------------------------------------------------------- 1 | let mkPackage = ../../package-sets/mkPackage.dhall 2 | 3 | let upstream = ../../package-sets/packages.dhall 4 | 5 | let overrides = {=} 6 | 7 | let additions = {=} 8 | 9 | in upstream ⫽ overrides ⫽ additions 10 | -------------------------------------------------------------------------------- /tests/04-memory/spago.dhall: -------------------------------------------------------------------------------- 1 | { name = 2 | "purec-test-memory" 3 | , dependencies = 4 | [] : List Text 5 | , packages = 6 | ./packages.dhall 7 | , sources = 8 | [ "src/**/*.purs", "test/**/*.purs" ] 9 | } 10 | -------------------------------------------------------------------------------- /tests/04-memory/src/Main.c: -------------------------------------------------------------------------------- 1 | #include "Main.h" 2 | 3 | PURS_FFI_FUNC_2(Main_sub, x, y) { 4 | return purs_any_int(purs_any_force_int(x) - purs_any_force_int(y)); 5 | } 6 | -------------------------------------------------------------------------------- /tests/04-memory/src/Main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | #include "runtime/purescript.h" 5 | 6 | PURS_FFI_EXPORT(Main_sub); 7 | 8 | #endif // MAIN_H 9 | -------------------------------------------------------------------------------- /tests/04-memory/src/Main.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | data Unit = Unit 4 | type Effect a = Unit -> a 5 | 6 | foreign import sub :: Int -> Int -> Int 7 | 8 | main :: Effect Int 9 | main _ = go { a: 100000 } 10 | where 11 | go { a: 0 } = 0 12 | go x = go (x { a = sub x.a 1 }) 13 | -------------------------------------------------------------------------------- /tests/05-datacons/.gitignore: -------------------------------------------------------------------------------- 1 | /bower_components/ 2 | /node_modules/ 3 | /.pulp-cache/ 4 | /output/ 5 | /generated-docs/ 6 | /.psc-package/ 7 | /.psc* 8 | /.purs* 9 | /.psa* 10 | /.spago 11 | -------------------------------------------------------------------------------- /tests/05-datacons/Makefile: -------------------------------------------------------------------------------- 1 | default: main 2 | .PHONY: default 3 | 4 | PUREC_DIR := ../.. 5 | include $(PUREC_DIR)/mk/target.mk 6 | 7 | $(eval $(call purs_mk_target,main,Main,src)) 8 | -------------------------------------------------------------------------------- /tests/05-datacons/packages.dhall: -------------------------------------------------------------------------------- 1 | let mkPackage = ../../package-sets/mkPackage.dhall 2 | 3 | let upstream = ../../package-sets/packages.dhall 4 | 5 | let overrides = {=} 6 | 7 | let additions = {=} 8 | 9 | in upstream ⫽ overrides ⫽ additions 10 | -------------------------------------------------------------------------------- /tests/05-datacons/spago.dhall: -------------------------------------------------------------------------------- 1 | { name = 2 | "purec-test-datacons" 3 | , dependencies = 4 | [] : List Text 5 | , packages = 6 | ./packages.dhall 7 | , sources = 8 | [ "src/**/*.purs", "test/**/*.purs" ] 9 | } 10 | -------------------------------------------------------------------------------- /tests/05-datacons/src/Main.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | data Unit = Unit 4 | type Effect a = Unit -> a 5 | data Maybe a = Just a | Nothing 6 | 7 | chain :: Effect Int -> Effect Int -> Effect Int 8 | chain a b = \_ -> 9 | let x = a Unit 10 | in 11 | case x of 12 | 0 -> b Unit 13 | n -> n 14 | 15 | infixl 5 chain as >> 16 | 17 | const :: ∀ a. a -> (∀ b. b -> a) 18 | const x _ = x 19 | 20 | main :: Effect Int 21 | main = 22 | let 23 | f = const (Just (Just 0)) 24 | g = const Nothing 25 | in (\_ -> 26 | case f 0 of 27 | Just (Just 0) -> 0 28 | Nothing -> 1 29 | _ -> 1) 30 | >> (\_ -> 31 | case f 1 of 32 | Just (Just 0) -> 0 33 | Nothing -> 1 34 | _ -> 1) 35 | >> (\_ -> 36 | case g 2 of 37 | Nothing -> 0 38 | Just _ -> 1) 39 | -------------------------------------------------------------------------------- /tests/06-typeclasses/.gitignore: -------------------------------------------------------------------------------- 1 | /bower_components/ 2 | /node_modules/ 3 | /.pulp-cache/ 4 | /output/ 5 | /generated-docs/ 6 | /.psc-package/ 7 | /.psc* 8 | /.purs* 9 | /.psa* 10 | /.spago 11 | -------------------------------------------------------------------------------- /tests/06-typeclasses/Makefile: -------------------------------------------------------------------------------- 1 | default: main 2 | .PHONY: default 3 | 4 | PUREC_DIR := ../.. 5 | include $(PUREC_DIR)/mk/target.mk 6 | 7 | $(eval $(call purs_mk_target,main,Main,src)) 8 | -------------------------------------------------------------------------------- /tests/06-typeclasses/packages.dhall: -------------------------------------------------------------------------------- 1 | let mkPackage = ../../package-sets/mkPackage.dhall 2 | 3 | let upstream = ../../package-sets/packages.dhall 4 | 5 | let overrides = {=} 6 | 7 | let additions = {=} 8 | 9 | in upstream ⫽ overrides ⫽ additions 10 | -------------------------------------------------------------------------------- /tests/06-typeclasses/spago.dhall: -------------------------------------------------------------------------------- 1 | { name = 2 | "purec-test-datacons" 3 | , dependencies = 4 | [] : List Text 5 | , packages = 6 | ./packages.dhall 7 | , sources = 8 | [ "src/**/*.purs", "test/**/*.purs" ] 9 | } 10 | -------------------------------------------------------------------------------- /tests/06-typeclasses/src/Main.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | data Unit = Unit 4 | type Effect a = Unit -> a 5 | 6 | chain :: Effect Int -> Effect Int -> Effect Int 7 | chain a b = \_ -> 8 | let x = a Unit 9 | in 10 | case x of 11 | 0 -> b Unit 12 | n -> n 13 | 14 | infixl 5 chain as >> 15 | 16 | class FakeMonoid m where 17 | mempty :: m 18 | 19 | instance arrayFakeMonoid :: FakeMonoid (Array a) where 20 | mempty = [] 21 | 22 | class Foo a where 23 | foo :: a -> { bar :: a } 24 | bar :: ∀ m. FakeMonoid m => a -> m 25 | 26 | instance fooInt :: Foo Int where 27 | foo i = { bar: i } 28 | bar _ = mempty 29 | 30 | main :: Effect Int 31 | main = 32 | (\_ -> (foo 0).bar) >> 33 | (\_ -> case bar 0 of 34 | [] -> 0 35 | _ -> 1) 36 | -------------------------------------------------------------------------------- /tests/10-prelude/Makefile: -------------------------------------------------------------------------------- 1 | default: main 2 | .PHONY: default 3 | 4 | PUREC_DIR := ../.. 5 | include $(PUREC_DIR)/mk/target.mk 6 | 7 | main: .spago 8 | 9 | main_CFLAGS = -g 10 | main_LD_FLAGS = -lm 11 | 12 | $(eval $(call purs_mk_target,main,Main,src)) 13 | -------------------------------------------------------------------------------- /tests/10-prelude/spago.dhall: -------------------------------------------------------------------------------- 1 | { name = "purec-test-prelude" 2 | , dependencies = [ "prelude" ] 3 | , packages = ../../package-sets/packages.dhall 4 | , sources = [ "src/**/*.purs", "test/**/*.purs" ] 5 | } 6 | -------------------------------------------------------------------------------- /tests/10-prelude/src/Main.h: -------------------------------------------------------------------------------- 1 | #ifndef Main_H 2 | #define Main_H 3 | 4 | #include 5 | 6 | PURS_FFI_FUNC_2(Main_putStrLn, s_, _) { 7 | const purs_str_t * s = purs_any_force_string(s_); 8 | PURS_RC_RELEASE(s); 9 | return purs_any_int_zero; 10 | } 11 | 12 | #endif // Main_H 13 | -------------------------------------------------------------------------------- /tests/10-prelude/src/Main.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | 5 | type Effect a = Unit -> a 6 | 7 | chainE :: Effect Int -> Effect Int -> Effect Int 8 | chainE a b = \_ -> 9 | let x = a unit 10 | in 11 | case x of 12 | 0 -> b unit 13 | n -> n 14 | 15 | infixl 5 chainE as >> 16 | 17 | pureE :: ∀ a. a -> Effect a 18 | pureE n _ = n 19 | 20 | check :: Boolean -> Effect Int 21 | check = pureE <<< if _ then 0 else 1 22 | 23 | runE :: ∀ a. Effect a -> a 24 | runE f = f unit 25 | 26 | foreign import putStrLn :: String -> Effect Int 27 | 28 | main :: Effect Int 29 | main = 30 | let 31 | x = pureE 5 32 | y = pureE 2 33 | a = pureE $ runE x + runE y 34 | z = pureE $ runE x * runE y 35 | b = pureE $ runE x - runE y 36 | c = pureE $ runE x / runE y 37 | in 38 | check (runE x == 5) 39 | >> check (runE a == 7) 40 | >> check (runE b == 3) 41 | >> check (runE c == 2) 42 | >> check (show ([] :: Array Int) == "[]") 43 | >> check (show [ 99 ] == "[99]") 44 | >> check (show [ 1, 2, 3 ] == "[1, 2, 3]") 45 | >> check (show "" == "\"\"") 46 | >> check (show "\"" == "\"\"\"") 47 | >> check (show {} == "{}") 48 | >> check (show { a: [ 1 ] } == "{ a: [1] }") 49 | >> check ([ 1, 2, 3 ] == [ 1, 2, 3 ]) 50 | >> check (map show [ 1, 2, 3 ] == [ "1", "2", "3" ]) 51 | >> check (show (map show [ 1, 2, 3 ]) == "[\"1\", \"2\", \"3\"]") 52 | >> check (map (_ * 3) [ 1, 2, 3 ] == [ 3, 6, 9 ]) 53 | >> check (pure 3 == [ 3 ]) 54 | >> check (map identity ([] :: Array Int) == []) 55 | -------------------------------------------------------------------------------- /tests/11-effects/Makefile: -------------------------------------------------------------------------------- 1 | default: main 2 | .PHONY: default 3 | 4 | PUREC_DIR := ../.. 5 | include $(PUREC_DIR)/mk/target.mk 6 | 7 | main: .spago 8 | 9 | main_CFLAGS = -g 10 | main_LD_FLAGS = -lm 11 | 12 | $(eval $(call purs_mk_target,main,Main,src)) 13 | -------------------------------------------------------------------------------- /tests/11-effects/spago.dhall: -------------------------------------------------------------------------------- 1 | { name = 2 | "purec-test-effects" 3 | , dependencies = 4 | [ "prelude", "effect" ] 5 | , packages = 6 | ../../package-sets/packages.dhall 7 | , sources = 8 | [ "src/**/*.purs", "test/**/*.purs" ] 9 | } 10 | -------------------------------------------------------------------------------- /tests/11-effects/src/Main.h: -------------------------------------------------------------------------------- 1 | #ifndef Main_H 2 | #define Main_H 3 | 4 | #include 5 | 6 | PURS_FFI_FUNC_1(Main_someStr, _) { 7 | const purs_str_t *s = purs_str_new("%s", "hi!"); 8 | return purs_any_string(s); 9 | } 10 | 11 | PURS_FFI_FUNC_2(Main_putStrLn, s_, _) { 12 | const purs_str_t * s = purs_any_force_string(s_); 13 | printf("%s\n", s->data); 14 | PURS_RC_RELEASE(s); 15 | return purs_any_int_zero; 16 | } 17 | 18 | #endif // Main_H 19 | -------------------------------------------------------------------------------- /tests/11-effects/src/Main.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Effect.Unsafe 6 | 7 | foreign import putStrLn :: String -> Effect Int 8 | foreign import someStr :: Effect String 9 | 10 | main :: Effect Int 11 | main = 12 | let message = unsafePerformEffect someStr 13 | in bind (void (pure { foo: "bar" })) \_ -> 14 | bind someStr \s -> 15 | bind (putStrLn s) \_ -> 16 | bind someStr \s' -> 17 | bind (putStrLn (s <> "and" <> s')) \_ -> 18 | putStrLn "world" 19 | -------------------------------------------------------------------------------- /tests/12-rec-fns/Makefile: -------------------------------------------------------------------------------- 1 | default: main 2 | .PHONY: default 3 | 4 | CFLAGS = -g3 -O0 5 | 6 | PUREC_DIR := ../.. 7 | include $(PUREC_DIR)/mk/target.mk 8 | 9 | main: .spago 10 | 11 | $(eval $(call purs_mk_target,main,Main,src)) 12 | -------------------------------------------------------------------------------- /tests/12-rec-fns/spago.dhall: -------------------------------------------------------------------------------- 1 | { name = 2 | "purec-test-effects" 3 | , dependencies = 4 | [ "prelude", "effect" ] 5 | , packages = 6 | ../../package-sets/packages.dhall 7 | , sources = 8 | [ "src/**/*.purs", "test/**/*.purs" ] 9 | } 10 | -------------------------------------------------------------------------------- /tests/main.stub.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "runtime/purescript.h" 6 | 7 | #include ".purec-work/lib/Main.h" 8 | 9 | int main(void) { 10 | return purs_any_get_int(purs_any_app(Main_main_$, purs_any_null)); 11 | } 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/1110.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data X a = X 7 | 8 | x :: forall a. X a 9 | x = X 10 | 11 | type Y = { x :: X Int } 12 | 13 | test :: forall m. Monad m => m Y 14 | test = pure { x: x } 15 | 16 | type Z t = forall x. t x -> (forall a. t a) -> t x 17 | 18 | class C t where c :: Z t 19 | 20 | instance cA :: C Array where 21 | c x _ = x 22 | 23 | test2 :: forall m. Monad m => m { ccc :: Z Array } 24 | test2 = pure { ccc: (c :: Z Array) } 25 | 26 | main = log "Done" 27 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/1185.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | data Person = Person String Boolean 6 | 7 | getName :: Person -> String 8 | getName p = case p of 9 | Person name true -> name 10 | _ -> "Unknown" 11 | 12 | name :: String 13 | name = getName (Person "John Smith" true) 14 | 15 | main = log "Done" 16 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/1335.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | x :: forall a. a -> String 7 | x a = y "Test" 8 | where 9 | y :: forall a. Show a => a -> String 10 | y a = show (a :: a) 11 | 12 | main = do 13 | log (x 0) 14 | log "Done" 15 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/1570.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | test :: forall a. a -> a 6 | test = \(x :: a) -> x 7 | 8 | main = log "Done" 9 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/1664.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Effect.Console 6 | 7 | data Identity a = Identity a 8 | 9 | newtype IdentityEff a = IdentityEff (Effect (Identity a)) 10 | 11 | test :: forall a. IdentityEff a -> IdentityEff Unit 12 | test (IdentityEff action) = IdentityEff $ do 13 | (Identity x :: Identity _) <- action 14 | pure $ Identity unit 15 | 16 | main = log "Done" 17 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/1697.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | _2 :: forall a. a -> a 7 | _2 a = a 8 | 9 | x :: forall m. Monad m => m Unit 10 | x = do 11 | _ <- pure unit 12 | pure unit 13 | 14 | y :: forall m. Monad m => m Unit 15 | y = do 16 | _ <- pure unit 17 | pure unit 18 | 19 | wtf :: forall m. Monad m => m Unit 20 | wtf = do 21 | _ <- pure unit 22 | let tmp = _2 1 23 | pure unit 24 | 25 | main = log "Done" 26 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/1807.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | fn = _.b.c.d 7 | a = {b:{c:{d:2}}} 8 | 9 | d :: Int 10 | d = fn a + a.b.c.d 11 | 12 | main = if fn a + a.b.c.d == 4 13 | then log "Done" 14 | else log "Fail" 15 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/1881.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | foo = 6 | 1 7 | 8 | bar 9 | = 2 10 | 11 | baz 12 | = 13 | 3 14 | 15 | qux 16 | = 17 | 3 18 | 19 | main = log "Done" 20 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/1991.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | singleton :: forall a. a -> Array a 7 | singleton x = [x] 8 | 9 | empty :: forall a. Array a 10 | empty = [] 11 | 12 | foldMap :: forall a m. Semigroup m => (a -> m) -> Array a -> m 13 | foldMap f [a, b, c, d, e] = f a <> f b <> f c <> f d <> f e 14 | foldMap f xs = foldMap f xs -- spin, not used 15 | 16 | regression :: Array Int 17 | regression = 18 | let as = [1,2,3,4,5] 19 | as' = foldMap (\x -> if 1 < x && x < 4 then singleton x else empty) as 20 | in as' 21 | 22 | main = log "Done" 23 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2018.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import A (foo) 5 | import B (Foo(..)) 6 | import Effect (Effect) 7 | import Effect.Console (log) 8 | 9 | main :: Effect Unit 10 | main = do 11 | let tmp = foo X 12 | log "Done" 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2018/A.purs: -------------------------------------------------------------------------------- 1 | module A where 2 | 3 | import B as Main 4 | 5 | -- Prior to the 2018 fix this would be detected as a cycle between A and Main. 6 | foo ∷ Main.Foo → Main.Foo 7 | foo x = x 8 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2018/B.purs: -------------------------------------------------------------------------------- 1 | module B where 2 | 3 | data Foo = X | Y 4 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2049.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data List a = Cons a (List a) | Nil 7 | 8 | infixr 6 Cons as : 9 | 10 | f :: List { x :: Int, y :: Int } -> Int 11 | f ( r@{ x } : _) = x + r.y 12 | f _ = 0 13 | 14 | main = log "Done" 15 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2136.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | main = 7 | if (negate (bottom :: Int) > top) 8 | then log "Fail" 9 | else log "Done" 10 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2138.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | import Lib (A(B,C)) 6 | 7 | main = log "Done" 8 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2138/Lib.purs: -------------------------------------------------------------------------------- 1 | module Lib (A(..), A) where 2 | 3 | data A = B | C 4 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2172.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | PURS_FFI_VALUE(Main_a$, PURS_ANY_NUM(0.0)); 4 | PURS_FFI_VALUE(Main_b$, PURS_ANY_NUM(1.0)); 5 | PURS_FFI_VALUE(Main_c$, PURS_ANY_NUM(2.0)); 6 | PURS_FFI_VALUE(Main_d$, PURS_ANY_NUM(3.0)); 7 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2172.h: -------------------------------------------------------------------------------- 1 | #ifndef Main_H 2 | #define Main_H 3 | 4 | #include 5 | 6 | PURS_FFI_EXPORT(Main_a$); 7 | PURS_FFI_EXPORT(Main_b$); 8 | PURS_FFI_EXPORT(Main_c$); 9 | PURS_FFI_EXPORT(Main_d$); 10 | 11 | #endif // Main_H 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2172.js: -------------------------------------------------------------------------------- 1 | exports['a\''] = 0; 2 | exports["\x62\x27"] = 1; 3 | // NOTE: I wanted to use "\c'" here, but langauge-javascript doesn't support it... 4 | exports["c'"] = 2; 5 | exports["\u0064\u0027"] = 3; 6 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2172.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | foreign import a' :: Number 6 | foreign import b' :: Number 7 | foreign import c' :: Number 8 | foreign import d' :: Number 9 | 10 | main = log "Done" 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2197-1.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console 4 | import Prim as P 5 | 6 | type Number = P.Number 7 | type Test = {} 8 | 9 | z :: Number 10 | z = 0.0 11 | 12 | main = log "Done" 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2197-2.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console 4 | import Prim (Int) 5 | 6 | type Number = Int 7 | 8 | z :: Number 9 | z = 0 10 | 11 | main = log "Done" 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2252.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | data T a = T 6 | 7 | ti :: T Int 8 | ti = T 9 | 10 | t :: forall a. T a 11 | t = T 12 | 13 | xs = [ti, t, t] 14 | 15 | main = log "Done" 16 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2288.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Effect.Console 6 | import Data.Array 7 | import Data.Array.Partial as P 8 | import Partial.Unsafe 9 | 10 | length :: forall a. Array a -> Int 11 | length = go 0 where 12 | go acc arr = 13 | if null arr 14 | then acc 15 | else go (acc + 1) (unsafePartial P.tail arr) 16 | 17 | main = do 18 | logShow (length (1 .. 10000)) 19 | log "Done" 20 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2378.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | class Foo (a :: Symbol) 6 | 7 | instance fooX :: Foo "x" 8 | 9 | main = log "Done" 10 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2438.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | done :: String 6 | done = {"𝌆": "Done"}."𝌆" 7 | 8 | main = log done 9 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2609.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Eg (Foo'(Bar'), (:->)) 5 | import Effect (Effect) 6 | import Effect.Console (log) 7 | 8 | bar' :: Foo' 9 | bar' = 4 :-> 5 10 | 11 | main :: Effect Unit 12 | main = case bar' of Bar' l r -> log "Done" 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2609/Eg.purs: -------------------------------------------------------------------------------- 1 | module Eg (Foo'(Bar'), (:->)) where 2 | 3 | data Foo' = Bar' Int Int 4 | 5 | infix 4 Bar' as :-> 6 | 7 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2616.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | newtype F r a = F { x :: a | r } 7 | 8 | unF :: forall r a. F r a -> { x :: a | r } 9 | unF (F x) = x 10 | 11 | derive instance functorF :: Functor (F r) 12 | 13 | main = log (unF (map identity (F { x: "Done", y: 42 }))).x 14 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2626.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | f = \(x :: forall a. a -> a) -> x x 6 | 7 | test1 = (f \x -> x) 1 8 | 9 | g = \(x :: (forall a. a -> a) -> Int) -> x (\y -> y) 10 | 11 | test2 = g \f -> if f true then f 0 else f 1 12 | 13 | main = log "Done" 14 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2663.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Prim.TypeError (class Warn, Text) 5 | import Effect.Console (log) 6 | 7 | foo :: forall t. Warn (Text "Example") => t -> t 8 | foo x = x 9 | 10 | main = when (foo 42 == 42) $ log "Done" 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2689.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console 5 | import Data.Array.Partial 6 | import Partial.Unsafe 7 | 8 | sumTCObug = go identity where 9 | go f 0 = f 10 | go f n = 11 | let 12 | f' a = n + a 13 | in 14 | go f' 0 15 | 16 | sumTCObug' = go identity where 17 | go f 0 = f 18 | go f n = go (\a -> n + a) 0 19 | 20 | count :: forall a. (a -> Boolean) -> Array a -> Int 21 | count p = count' 0 where 22 | count' acc [] = acc 23 | count' acc xs = 24 | let h = unsafePartial head xs 25 | in count' (acc + if p h then 1 else 0) (unsafePartial tail xs) 26 | 27 | main = do 28 | let x = sumTCObug 7 3 29 | y = sumTCObug' 7 3 30 | z = count (_ > 0) [-1, 0, 1] 31 | logShow x 32 | logShow y 33 | logShow z 34 | if x == 10 && y == 10 && z == 1 35 | then log "Done" 36 | else log "Fail" 37 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2756.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect (Effect) 4 | import Effect.Console (log) 5 | import Prelude 6 | 7 | pu :: forall i. i -> Effect Unit 8 | pu _ = pure unit 9 | 10 | type C i = { pu :: i -> Effect Unit } 11 | 12 | sampleC :: C Unit 13 | sampleC = { pu: pu } 14 | 15 | newtype Identity a = Id a 16 | 17 | sampleIdC :: Identity (C Unit) 18 | sampleIdC = Id { pu : pu } 19 | 20 | main = log "Done" 21 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2787.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console 5 | 6 | main 7 | | between 0 1 2 = log "Fail" 8 | | otherwise = log "Done" 9 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2795.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data X = X Int | Y 7 | 8 | x :: X -> Int 9 | x = case _ of 10 | Y -> 0 11 | X n | 1 <- n -> 1 12 | | otherwise -> 2 13 | 14 | main = log "Done" 15 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2803.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude ((+), (-), (==)) 4 | import Effect.Console (log) 5 | 6 | f :: Int -> Int -> Int 7 | f = (+) 8 | 9 | infixl 6 f as % 10 | 11 | g :: Int -> Int -> Int 12 | g a b = let f = (-) in a % b 13 | 14 | main = 15 | if g 10 5 == 15 16 | then log "Done" 17 | else log "Failed" 18 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2806.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data Stream a = Cons a (Stream a) 7 | 8 | step :: forall a. Stream a -> Stream a 9 | step (Cons _ xs) = xs 10 | 11 | head :: forall a. Stream a -> a 12 | head xs | Cons x _ <- step xs = x 13 | 14 | main = log "Done" 15 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2947.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data Foo = Foo 7 | 8 | instance eqFoo :: Eq Foo where 9 | eq _ _ = true 10 | 11 | main = log "Done" 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2958.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console 4 | 5 | data Nil 6 | data Snoc xs x 7 | 8 | infixl 1 type Snoc as :> 9 | 10 | type One = Nil :> Int 11 | type Two = Nil :> Int :> Int 12 | type Three = Nil :> Int :> Int :> Int 13 | 14 | main = log "Done" 15 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/2972.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | import Prelude (class Show, show) 5 | 6 | type I t = t 7 | 8 | newtype Id t = Id t 9 | 10 | instance foo :: Show (I t) => Show (Id t) where 11 | show (Id t) = "Done" 12 | 13 | main = log (show (Id "other")) 14 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/3114.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | 5 | import Data.Either 6 | import Data.Maybe 7 | import Data.Tuple 8 | import Effect 9 | import Effect.Console (log) 10 | import VendoredVariant 11 | import Data.Symbol 12 | 13 | type TestVariants = 14 | ( foo :: FProxy Maybe 15 | , bar :: FProxy (Tuple String) 16 | ) 17 | 18 | _foo :: SProxy "foo" 19 | _foo = SProxy 20 | 21 | _bar :: SProxy "bar" 22 | _bar = SProxy 23 | 24 | main :: Effect Unit 25 | main = do 26 | let 27 | -- with the type signatures on `a`, this compiles fine. 28 | case1 :: VariantF TestVariants Int → String 29 | case1 = case_ 30 | # on _foo (\a → "foo: " <> show (a :: Maybe Int)) 31 | # on _bar (\a → "bar: " <> show (a :: Tuple String Int)) 32 | 33 | -- without the type signature, this would complain about 34 | -- Could not match type 35 | -- Array 36 | -- with type 37 | -- Tuple String 38 | -- while trying to match the type FProxy Array 39 | -- with type FProxy (Tuple String) 40 | -- while solving type class constraint 41 | -- Prim.RowCons "baz" 42 | -- (FProxy t0) 43 | -- t1 44 | -- ( foo :: FProxy Maybe 45 | -- , bar :: FProxy (Tuple String) 46 | -- ) 47 | -- while inferring the type of `on _baz` 48 | case2 :: VariantF TestVariants Int → String 49 | case2 = case_ 50 | # on _foo (\a → "foo: " <> show a) 51 | # on _bar (\a → "bar: " <> show a) 52 | 53 | log "Done" 54 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/3114/VendoredVariant.purs: -------------------------------------------------------------------------------- 1 | module VendoredVariant where 2 | 3 | import Prelude 4 | 5 | import Prim.Row as Row 6 | 7 | import Unsafe.Coerce (unsafeCoerce) 8 | import Partial.Unsafe (unsafeCrashWith) 9 | import Data.Symbol 10 | 11 | data FProxy (k :: Type -> Type) = FProxy 12 | data VariantF (f :: # Type) a 13 | 14 | newtype VariantFRep f a = VariantFRep 15 | { type :: String 16 | , value :: f a 17 | , map :: forall x y. (x -> y) -> f x -> f y 18 | } 19 | 20 | case_ :: forall a b. VariantF () a -> b 21 | case_ r = unsafeCrashWith case unsafeCoerce r of 22 | VariantFRep v -> "failure on " <> v.type 23 | 24 | on 25 | :: forall sym f a b r1 r2 26 | . Row.Cons sym (FProxy f) r1 r2 27 | => IsSymbol sym 28 | => SProxy sym 29 | -> (f a -> b) 30 | -> (VariantF r1 a -> b) 31 | -> VariantF r2 a 32 | -> b 33 | on p f g r = 34 | case coerceY r of 35 | VariantFRep v | v.type == reflectSymbol p -> f v.value 36 | _ -> g (coerceR r) 37 | where 38 | coerceY :: VariantF r2 a -> VariantFRep f a 39 | coerceY = unsafeCoerce 40 | 41 | coerceR :: VariantF r2 a -> VariantF r1 a 42 | coerceR = unsafeCoerce 43 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/3125.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Data.Monoid (class Monoid, mempty) 5 | import Effect.Console (log, logShow) 6 | 7 | data B a = B a a 8 | 9 | memptyB :: forall a b. Monoid b => B (a -> b) 10 | memptyB = B l r where 11 | l _ = mempty 12 | r _ = mempty 13 | 14 | main = do 15 | logShow $ case (memptyB :: B (Int -> Array Unit)) of B l r -> l 0 == r 0 16 | log "Done" 17 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/3187-UnusedNameClash.purs: -------------------------------------------------------------------------------- 1 | module Main (main) where 2 | 3 | import Prelude ((+)) 4 | import Effect.Console (log) 5 | 6 | -- the __unused parameter used to get optimized away 7 | abuseUnused :: forall a. a -> a 8 | abuseUnused __unused = __unused 9 | 10 | main = do 11 | let explode = abuseUnused 0 + abuseUnused 0 12 | log "Done" 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/652.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | class Foo a b 7 | 8 | class Bar a c 9 | 10 | class (Foo a b, Bar a c) <= Baz a b c 11 | 12 | instance foo :: Foo (a -> b) a 13 | 14 | instance bar :: Bar (a -> b) b 15 | 16 | instance baz :: (Eq a) => Baz (a -> b) a b 17 | 18 | main = log "Done" 19 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/810.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data Maybe a = Nothing | Just a 7 | 8 | test :: forall a. Maybe a -> Maybe a 9 | test m = o.x 10 | where 11 | o = case m of Nothing -> { x : Nothing } 12 | Just a -> { x : Just a } 13 | 14 | main = log "Done" 15 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/862.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console 5 | 6 | id' = (\x -> x) <$> \y -> y 7 | 8 | main = log (id' "Done") 9 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/922.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | 5 | import Effect.Console 6 | 7 | class Default a where 8 | def :: a 9 | 10 | instance defaultString :: Default String where 11 | def = "Done" 12 | 13 | data I a = I a 14 | 15 | instance defaultI :: (Default a) => Default (I a) where 16 | def = I def 17 | 18 | main = do 19 | case def of 20 | I s -> log s 21 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Ado.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | import Effect.Ref as Ref 6 | 7 | data Maybe a = Nothing | Just a 8 | 9 | instance functorMaybe :: Functor Maybe where 10 | map f Nothing = Nothing 11 | map f (Just x) = Just (f x) 12 | 13 | instance applyMaybe :: Apply Maybe where 14 | apply (Just f) (Just x) = Just (f x) 15 | apply _ _ = Nothing 16 | 17 | instance applicativeMaybe :: Applicative Maybe where 18 | pure = Just 19 | 20 | test1 = \_ -> ado 21 | in "abc" 22 | 23 | test2 = \_ -> ado 24 | x <- Just 1.0 25 | y <- Just 2.0 26 | in x + y 27 | 28 | test3 = \_ -> ado 29 | _ <- Just 1.0 30 | _ <- Nothing :: Maybe Number 31 | in 2.0 32 | 33 | test4 mx my = ado 34 | x <- mx 35 | y <- my 36 | in x + y + 1.0 37 | 38 | test5 mx my mz = ado 39 | x <- mx 40 | y <- my 41 | let sum = x + y 42 | z <- mz 43 | in z + sum + 1.0 44 | 45 | test6 mx = \_ -> ado 46 | let 47 | f :: forall a. Maybe a -> a 48 | f (Just x) = x 49 | in f mx 50 | 51 | test8 = \_ -> ado 52 | in (ado 53 | in 1.0) 54 | 55 | test9 = \_ -> (+) <$> Just 1.0 <*> Just 2.0 56 | 57 | test10 _ = ado 58 | let 59 | f x = g x * 3.0 60 | g x = f x / 2.0 61 | in f 10.0 62 | 63 | test11 = \_ -> ado 64 | x <- pure 1 65 | y <- pure "A" 66 | z <- pure [] 67 | in show (x :: Int) <> y <> show (z :: Array Int) 68 | 69 | main = do 70 | r <- Ref.new "X" 71 | log =<< ado 72 | _ <- Ref.write "D" r 73 | a <- Ref.read r 74 | b <- pure "o" 75 | let c = "n" 76 | d <- pure "e" 77 | in a <> b <> c <> d 78 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/AppendInReverse.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Data.Symbol (SProxy(..)) 5 | import Prim.Symbol (class Append) 6 | import Effect.Console (log) 7 | 8 | class Balanced (sym :: Symbol) 9 | 10 | instance balanced1 :: Balanced "" 11 | else 12 | instance balanced2 13 | :: ( Append "(" sym1 sym 14 | , Append sym2 ")" sym1 15 | , Balanced sym2 16 | ) => Balanced sym 17 | 18 | balanced :: forall sym. Balanced sym => SProxy sym -> String 19 | balanced _ = "ok" 20 | 21 | b0 :: String 22 | b0 = balanced (SProxy :: SProxy "") 23 | 24 | b1 :: String 25 | b1 = balanced (SProxy :: SProxy "()") 26 | 27 | b2 :: String 28 | b2 = balanced (SProxy :: SProxy "(())") 29 | 30 | b3 :: String 31 | b3 = balanced (SProxy :: SProxy "((()))") 32 | 33 | main = do 34 | log b0 35 | log b1 36 | log b2 37 | log b3 38 | log "Done" 39 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Applicative.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | class Applicative f where 6 | pure :: forall a. a -> f a 7 | apply :: forall a b. f (a -> b) -> f a -> f b 8 | 9 | data Maybe a = Nothing | Just a 10 | 11 | instance applicativeMaybe :: Applicative Maybe where 12 | pure = Just 13 | apply (Just f) (Just a) = Just (f a) 14 | apply _ _ = Nothing 15 | 16 | main = log "Done" 17 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ArrayType.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | class Pointed p where 7 | point :: forall a. a -> p a 8 | 9 | instance pointedArray :: Pointed Array where 10 | point a = [a] 11 | 12 | main = log "Done" 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Auto.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data Auto s i o = Auto { state :: s, step :: s -> i -> o } 7 | 8 | type SomeAuto i o = forall r. (forall s. Auto s i o -> r) -> r 9 | 10 | exists :: forall s i o. s -> (s -> i -> o) -> SomeAuto i o 11 | exists = \state step f -> f (Auto { state: state, step: step }) 12 | 13 | run :: forall i o. SomeAuto i o -> i -> o 14 | run = \s i -> s (\a -> case a of Auto a -> a.step a.state i) 15 | 16 | main = log "Done" 17 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/AutoPrelude.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | f x = x * 10.0 7 | g y = y - 10.0 8 | 9 | main = do 10 | log $ show $ (f <<< g) 100.0 11 | log "Done" 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/AutoPrelude2.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Prelude as P 5 | import Effect.Console 6 | 7 | f :: forall a. a -> a 8 | f = P.identity 9 | 10 | main = P.($) log ((f P.<<< f) "Done") 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/BindersInFunctions.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Partial.Unsafe (unsafePartial) 5 | import Test.Assert (assert') 6 | import Effect (Effect) 7 | import Effect.Console (log) 8 | 9 | snd :: forall a. Partial => Array a -> a 10 | snd = \[_, y] -> y 11 | 12 | main :: Effect _ 13 | main = do 14 | let ts = unsafePartial (snd [1.0, 2.0]) 15 | assert' "Incorrect result from 'snd'." (ts == 2.0) 16 | log "Done" 17 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/BindingGroups.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | foo = bar 7 | where bar r = r + 1.0 8 | 9 | r = foo 2.0 10 | 11 | main = log "Done" 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/BlockString.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | foo :: String 7 | foo = """foo""" 8 | 9 | main = log "Done" 10 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/CaseInDo.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Partial.Unsafe (unsafeCrashWith) 5 | import Effect.Console 6 | import Effect 7 | 8 | doIt :: Effect Boolean 9 | doIt = pure true 10 | 11 | set = do 12 | log "Testing..." 13 | case 0 of 14 | 0 -> doIt 15 | _ -> pure false 16 | 17 | main = do 18 | b <- set 19 | case b of 20 | true -> log "Done" 21 | false -> unsafeCrashWith "Failed" 22 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/CaseInputWildcard.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect (Effect) 5 | import Effect.Console (log) 6 | 7 | data Foo = X | Y 8 | 9 | what ∷ Foo → Int → Boolean → Foo 10 | what x = case _, x, _ of 11 | 0, X, true → X 12 | 0, Y, true → X 13 | _, _, _ → Y 14 | 15 | main :: Effect Unit 16 | main = do 17 | let tmp = what Y 0 true 18 | log "Done" 19 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/CaseMultipleExpressions.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Partial.Unsafe (unsafeCrashWith) 5 | import Effect.Console 6 | import Effect 7 | 8 | doIt :: Effect Boolean 9 | doIt = pure true 10 | 11 | set = do 12 | log "Testing..." 13 | case 42, 10 of 14 | 42, 10 -> doIt 15 | _ , _ -> pure false 16 | 17 | main = do 18 | b <- set 19 | case b of 20 | true -> log "Done" 21 | false -> unsafeCrashWith "Failed" 22 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/CaseStatement.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data A = A | B | C 7 | 8 | f a _ A = a 9 | f _ a B = a 10 | f _ _ C = "Done" 11 | 12 | g a _ A = a 13 | g _ b B = b 14 | g _ _ C = C 15 | 16 | data M a = N | J a 17 | 18 | h f N a = a 19 | h f a N = a 20 | h f (J a) (J b) = J (f a b) 21 | 22 | main = log $ f "Done" "Failed" A 23 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/CheckFunction.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | test = ((\x -> x+1.0) >>> (\x -> x*2.0)) 4.0 7 | 8 | main = log "Done" 9 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/CheckSynonymBug.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | length :: forall a. Array a -> Int 7 | length _ = 0 8 | 9 | type Foo a = Array a 10 | 11 | foo _ = length ([] :: Foo Number) 12 | 13 | main = log "Done" 14 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/CheckTypeClass.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data Bar a = Bar 7 | data Baz 8 | 9 | class Foo a where 10 | foo :: Bar a -> Baz 11 | 12 | foo_ :: forall a. Foo a => a -> Baz 13 | foo_ x = foo ((mkBar :: forall a. Foo a => a -> Bar a) x) 14 | 15 | mkBar :: forall a. a -> Bar a 16 | mkBar _ = Bar 17 | 18 | main = log "Done" 19 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Church.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | type List a = forall r. r -> (a -> r -> r) -> r 6 | 7 | empty :: forall a. List a 8 | empty = \r f -> r 9 | 10 | cons :: forall a. a -> List a -> List a 11 | cons = \a l r f -> f a (l r f) 12 | 13 | append :: forall a. List a -> List a -> List a 14 | append = \l1 l2 r f -> l2 (l1 r f) f 15 | 16 | test = append (cons 1 empty) (cons 2 empty) 17 | 18 | main = log "Done" 19 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ClassRefSyntax.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Lib (class X, go) 4 | import Effect.Console (log) 5 | 6 | go' :: forall a. X a => a -> a 7 | go' = go 8 | 9 | main = log "Done" 10 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ClassRefSyntax/Lib.purs: -------------------------------------------------------------------------------- 1 | module Lib (class X, go) where 2 | 3 | class X a where 4 | go :: a -> a 5 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Collatz.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Control.Monad.ST as ST 6 | import Control.Monad.ST.Ref as STRef 7 | import Effect.Console (log, logShow) 8 | 9 | collatz :: Int -> Int 10 | collatz n = ST.run (do 11 | r <- STRef.new n 12 | count <- STRef.new 0 13 | ST.while (map (_ /= 1) (STRef.read r)) do 14 | _ <- STRef.modify (_ + 1) count 15 | m <- STRef.read r 16 | void $ STRef.write (if m `mod` 2 == 0 then m / 2 else 3 * m + 1) r 17 | STRef.read count) 18 | 19 | main = do 20 | logShow $ collatz 1000 21 | log "Done" 22 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Comparisons.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Effect.Console 6 | import Test.Assert 7 | 8 | main = do 9 | assert (1.0 < 2.0) 10 | assert (2.0 == 2.0) 11 | assert (3.0 > 1.0) 12 | assert ("a" < "b") 13 | assert ("a" == "a") 14 | assert ("z" > "a") 15 | log "Done" 16 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Conditional.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | fns = \f -> if f true then f else \x -> x 6 | 7 | not = \x -> if x then false else true 8 | 9 | main = log "Done" 10 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Console.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Effect.Console 6 | 7 | replicateM_ :: forall m a. Monad m => Number -> m a -> m Unit 8 | replicateM_ 0.0 _ = pure unit 9 | replicateM_ n act = do 10 | _ <- act 11 | replicateM_ (n - 1.0) act 12 | 13 | main = do 14 | replicateM_ 10.0 (log "Hello World!") 15 | log "Done" 16 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ConstraintInference.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | shout = log <<< (_ <> "!") <<< show 7 | 8 | main = do 9 | shout "Test" 10 | log "Done" 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ConstraintParens.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | class Foo a where 7 | foo ∷ a → a 8 | 9 | test ∷ ∀ a. (Foo a) ⇒ a → a 10 | test = foo 11 | 12 | main = log "Done" 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ConstraintParsingIssue.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console 4 | 5 | class X a 6 | 7 | instance x :: X (Array (Array a)) => X (Array a) 8 | 9 | main = log "Done" 10 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ContextSimplification.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console 5 | 6 | shout = log <<< (_ <> "!") <<< show 7 | 8 | -- Here, we should simplify the context so that only one Show 9 | -- constraint is added. 10 | usesShowTwice true = shout 11 | usesShowTwice false = logShow 12 | 13 | main = do 14 | usesShowTwice true "Test" 15 | log "Done" 16 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/DataAndType.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data A = A B 7 | 8 | type B = A 9 | 10 | main = log "Done" 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/DataConsClassConsOverlapOk.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | import Prim.Row (class Cons) 5 | 6 | data Cons = Cons 7 | 8 | main = log "Done" 9 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/DctorName.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | newtype Bar' = Bar' Int 7 | 8 | data Foo' = Foo' Bar' 9 | 10 | data Baz'' = Baz'' | Baz' 11 | 12 | f ∷ Foo' → Boolean 13 | f a = case a of Foo' b → true 14 | 15 | f' ∷ Boolean 16 | f' = f $ Foo' $ Bar' 0 17 | 18 | g ∷ Baz'' → Int 19 | g Baz'' = 0 20 | g Baz' = 1 21 | 22 | g' ∷ Int 23 | g' = g Baz'' 24 | 25 | h ∷ Bar' → Int 26 | h (Bar' x) 27 | | x <= 10 = x * 2 28 | | otherwise = 10 29 | 30 | h' ∷ Int 31 | h' = h $ Bar' 4 32 | 33 | main = log "Done" 34 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/DctorOperatorAlias.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude (Unit, bind, discard, (==)) 4 | import Effect (Effect) 5 | import Effect.Console (log) 6 | import Test.Assert (assert') 7 | import List (List(..), (:)) 8 | import List as L 9 | 10 | -- unqualified 11 | infixl 6 Cons as ! 12 | 13 | -- qualified 14 | infixl 6 L.Cons as !! 15 | 16 | get1 ∷ ∀ a. a → List a → a 17 | get1 y xs = case xs of 18 | _ : x : _ → x 19 | _ → y 20 | 21 | get2 ∷ ∀ a. a → List a → a 22 | get2 _ (_ : x : _) = x 23 | get2 y _ = y 24 | 25 | get3 ∷ ∀ a. a → List a → a 26 | get3 _ (_ ! (x ! _)) = x 27 | get3 y _ = y 28 | 29 | main ∷ Effect Unit 30 | main = do 31 | assert' "Incorrect result!" (get1 0 (1 : 2 : 3 : Nil) == 2) 32 | assert' "Incorrect result!" (get2 0 (1 ! (2 ! (3 ! Nil))) == 2) 33 | assert' "Incorrect result!" (get3 0.0 (1.0 : 2.0 : (3.0 ! Nil)) == 2.0) 34 | log "Done" 35 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/DctorOperatorAlias/List.purs: -------------------------------------------------------------------------------- 1 | module List where 2 | 3 | data List a = Cons a (List a) | Nil 4 | 5 | infixr 6 Cons as : 6 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/DeepArrayBinder.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Effect.Console (log) 6 | import Test.Assert 7 | 8 | data List a = Cons a (List a) | Nil 9 | 10 | match2 :: List Number -> Number 11 | match2 (Cons x (Cons y xs)) = x * y + match2 xs 12 | match2 _ = 0.0 13 | 14 | main = do 15 | let result = match2 (Cons 1.0 (Cons 2.0 (Cons 3.0 (Cons 4.0 (Cons 5.0 (Cons 6.0 (Cons 7.0 (Cons 8.0 (Cons 9.0 Nil))))))))) 16 | assert' "Incorrect result!" (result == 100.0) 17 | log "Done" 18 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/DeepCase.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log, logShow) 5 | 6 | f x y = 7 | let 8 | g = case y of 9 | 0.0 -> x 10 | x -> 1.0 + x * x 11 | in g + x + y 12 | 13 | main = do 14 | logShow $ f 1.0 10.0 15 | log "Done" 16 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/DeriveNewtype.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | import Data.Newtype 6 | 7 | type MyString = String 8 | 9 | newtype Test = Test MyString 10 | 11 | derive instance newtypeTest :: Newtype Test _ 12 | 13 | t :: Test 14 | t = wrap "hello" 15 | 16 | a :: String 17 | a = unwrap t 18 | 19 | newtype First a = First a 20 | 21 | derive instance newtypeFirst :: Newtype (First b) _ 22 | 23 | f :: First Int 24 | f = wrap 1 25 | 26 | i :: Int 27 | i = unwrap f 28 | 29 | main = log "Done" 30 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/DeriveWithNestedSynonyms.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | type L = {} 7 | data X = X L 8 | derive instance eqX :: Eq X 9 | 10 | type M = {} 11 | data Y = Y {foo :: M} 12 | derive instance eqY :: Eq Y 13 | 14 | type N = {} 15 | data Z = Z N 16 | derive instance eqZ :: Eq Z 17 | 18 | type Foo = String 19 | 20 | type Bar = { foo :: Foo } 21 | 22 | type Baz = { baz :: Bar } 23 | 24 | newtype T = T Baz 25 | 26 | derive instance eqT :: Eq T 27 | derive instance ordT :: Ord T 28 | 29 | main = log "Done" 30 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Deriving.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | import Test.Assert 6 | 7 | data V 8 | 9 | derive instance eqV :: Eq V 10 | 11 | derive instance ordV :: Ord V 12 | 13 | type MyString = String 14 | 15 | data X = X Int | Y MyString 16 | 17 | derive instance eqX :: Eq X 18 | 19 | derive instance ordX :: Ord X 20 | 21 | newtype Z = Z { left :: X, right :: X } 22 | 23 | derive instance eqZ :: Eq Z 24 | 25 | main = do 26 | assert $ X 0 == X 0 27 | assert $ X 0 /= X 1 28 | assert $ Y "Foo" == Y "Foo" 29 | assert $ Y "Foo" /= Y "Bar" 30 | assert $ X 0 < X 1 31 | assert $ X 0 < Y "Foo" 32 | assert $ Y "Bar" < Y "Baz" 33 | assert $ z == z 34 | log "Done" 35 | where 36 | z = Z { left: X 0, right: Y "Foo" } 37 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/DerivingFunctor.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Data.Eq (class Eq1) 5 | import Effect.Console (log) 6 | import Test.Assert 7 | 8 | type MyRecord a = { myField :: a } 9 | 10 | data M f a 11 | = M0 a (Array a) 12 | | M1 Int 13 | | M2 (f a) 14 | | M3 { foo :: Int, bar :: a, baz :: f a } 15 | | M4 (MyRecord a) 16 | 17 | derive instance eqM :: (Eq1 f, Eq a) => Eq (M f a) 18 | derive instance functorM :: Functor f => Functor (M f) 19 | 20 | data T a = T (forall t. Show t => t -> a) 21 | derive instance functorT :: Functor T 22 | 23 | type MA = M Array 24 | 25 | main = do 26 | assert $ map show (M0 0 [1, 2] :: MA Int) == M0 "0" ["1", "2"] 27 | assert $ map show (M1 0 :: MA Int) == M1 0 28 | assert $ map show (M2 [0, 1] :: MA Int) == M2 ["0", "1"] 29 | assert $ map show (M3 {foo: 0, bar: 1, baz: [2, 3]} :: MA Int) == M3 {foo: 0, bar: "1", baz: ["2", "3"]} 30 | assert $ (map show (M4 { myField: 42 })) == ((M4 { myField: "42" }) :: MA String) 31 | 32 | case map show (T \_ -> 42) of 33 | T f -> assert $ f "hello" == "42" 34 | _ -> assert false 35 | 36 | log "Done" 37 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Do.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data Maybe a = Nothing | Just a 7 | 8 | instance functorMaybe :: Functor Maybe where 9 | map f Nothing = Nothing 10 | map f (Just x) = Just (f x) 11 | 12 | instance applyMaybe :: Apply Maybe where 13 | apply (Just f) (Just x) = Just (f x) 14 | apply _ _ = Nothing 15 | 16 | instance applicativeMaybe :: Applicative Maybe where 17 | pure = Just 18 | 19 | instance bindMaybe :: Bind Maybe where 20 | bind Nothing _ = Nothing 21 | bind (Just a) f = f a 22 | 23 | instance monadMaybe :: Monad Maybe 24 | 25 | test1 = \_ -> do 26 | Just "abc" 27 | 28 | test2 = \_ -> do 29 | x <- Just 1.0 30 | y <- Just 2.0 31 | Just (x + y) 32 | 33 | test3 = \_ -> do 34 | _ <- Just 1.0 35 | _ <- Nothing :: Maybe Number 36 | Just 2.0 37 | 38 | test4 mx my = do 39 | x <- mx 40 | y <- my 41 | Just (x + y + 1.0) 42 | 43 | test5 mx my mz = do 44 | x <- mx 45 | y <- my 46 | let sum = x + y 47 | z <- mz 48 | Just (z + sum + 1.0) 49 | 50 | test6 mx = \_ -> do 51 | let 52 | f :: forall a. Maybe a -> a 53 | f (Just x) = x 54 | Just (f mx) 55 | 56 | test8 = \_ -> do 57 | Just (do 58 | Just 1.0) 59 | 60 | test9 = \_ -> (+) <$> Just 1.0 <*> Just 2.0 61 | 62 | test10 _ = do 63 | let 64 | f x = g x * 3.0 65 | g x = f x / 2.0 66 | Just (f 10.0) 67 | 68 | main = log "Done" 69 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Dollar.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | applyFn :: forall a b. (a -> b) -> a -> b 6 | applyFn f x = f x 7 | 8 | infixr 1000 applyFn as $ 9 | 10 | id x = x 11 | 12 | test1 x = id $ id $ id $ id $ x 13 | 14 | test2 x = id id $ id x 15 | 16 | main = log "Done" 17 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/DuplicateProperties.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data RProxy (r :: # Type) = RProxy 7 | 8 | data Proxy (a :: Type) = Proxy 9 | 10 | subtractX :: forall r a. RProxy (x :: a | r) -> RProxy r 11 | subtractX RProxy = RProxy 12 | 13 | extractX :: forall r a. RProxy (x :: a | r) -> Proxy a 14 | extractX RProxy = Proxy 15 | 16 | hasX :: forall r a b. RProxy (x :: a, y :: b | r) 17 | hasX = RProxy 18 | 19 | test1 = subtractX (subtractX hasX) 20 | 21 | test2 22 | :: forall r a b 23 | . RProxy (x :: a, x :: b, x :: Int | r) 24 | -> Proxy Int 25 | test2 x = extractX (subtractX (subtractX x)) 26 | 27 | main = log "Done" 28 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/EffFn.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | PURS_FFI_FUNC_UNCURRIED_3(Main_add3, _a, _b, _c) { 4 | return purs_any_string( 5 | purs_str_new( 6 | "%s%s%s", 7 | purs_any_unsafe_get_string(_a)->data, 8 | purs_any_unsafe_get_string(_b)->data, 9 | purs_any_unsafe_get_string(_c)->data)); 10 | } 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/EffFn.h: -------------------------------------------------------------------------------- 1 | #ifndef Main_H 2 | #define Main_H 3 | 4 | #include 5 | 6 | PURS_FFI_EXPORT(Main_add3); 7 | 8 | #endif // Main_H 9 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/EffFn.js: -------------------------------------------------------------------------------- 1 | exports.add3 = function (a,b,c) { return a + b + c; }; -------------------------------------------------------------------------------- /upstream/tests/purs/passing/EffFn.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | 5 | import Effect.Console (log) 6 | import Effect.Uncurried (EffectFn3, mkEffectFn7, runEffectFn3, runEffectFn7) 7 | import Test.Assert (assert) 8 | 9 | testBothWays = do 10 | res <- (runEffectFn7 $ mkEffectFn7 \x1 x2 x3 x4 x5 x6 x7 -> pure 42) 1 2 3 4 5 6 7 11 | assert $ res == 42 12 | 13 | foreign import add3 :: EffectFn3 String String String String 14 | 15 | testRunFn = do 16 | str <- runEffectFn3 add3 "a" "b" "c" 17 | assert $ str == "abc" 18 | 19 | main = do 20 | testBothWays 21 | testRunFn 22 | log "Done" 23 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/EmptyDataDecls.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Test.Assert 5 | import Effect.Console (log) 6 | 7 | data Z 8 | data S n 9 | 10 | data ArrayBox n a = ArrayBox (Array a) 11 | 12 | nil :: forall a. ArrayBox Z a 13 | nil = ArrayBox [] 14 | 15 | cons' :: forall a n. a -> ArrayBox n a -> ArrayBox (S n) a 16 | cons' x (ArrayBox xs) = ArrayBox $ append [x] xs 17 | 18 | main = case cons' 1 $ cons' 2 $ cons' 3 nil of 19 | ArrayBox [1, 2, 3] -> log "Done" 20 | _ -> assert' "Failed" false 21 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/EmptyRow.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data Foo r = Foo { | r } 7 | 8 | test :: Foo () 9 | test = Foo {} 10 | 11 | main = log "Done" 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/EmptyTypeClass.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Effect.Console 6 | 7 | head :: forall a. Partial => Array a -> a 8 | head [x] = x 9 | 10 | main :: Effect _ 11 | main = log "Done" 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/EntailsKindedType.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Effect.Console 6 | 7 | test x = show (x :: _ :: Type) 8 | 9 | main = do 10 | when (show (unit :: Unit :: Type) == "unit") (log "Done") 11 | when (test unit == "unit") (log "Done") 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Eq1Deriving.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Data.Eq (class Eq1) 5 | import Effect.Console (log) 6 | 7 | data Product a b = Product a b 8 | 9 | derive instance eqMu :: (Eq a, Eq b) => Eq (Product a b) 10 | derive instance eq1Mu :: Eq a => Eq1 (Product a) 11 | 12 | main = log "Done" 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Eq1InEqDeriving.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Data.Eq (class Eq1) 5 | import Effect.Console (log) 6 | 7 | newtype Mu f = In (f (Mu f)) 8 | 9 | derive instance eqMu :: Eq1 f => Eq (Mu f) 10 | 11 | main = log "Done" 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/EqOrd.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log, logShow) 5 | 6 | data Pair a b = Pair a b 7 | 8 | instance ordPair :: (Ord a, Ord b) => Ord (Pair a b) where 9 | compare (Pair a1 b1) (Pair a2 b2) = case compare a1 a2 of 10 | EQ -> compare b1 b2 11 | r -> r 12 | 13 | instance eqPair :: (Eq a, Eq b) => Eq (Pair a b) where 14 | eq (Pair a1 b1) (Pair a2 b2) = a1 == a2 && b1 == b2 15 | 16 | main = do 17 | logShow $ Pair 1.0 2.0 == Pair 1.0 2.0 18 | log "Done" 19 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ExplicitImportReExport.purs: -------------------------------------------------------------------------------- 1 | -- from #1244 2 | module Main where 3 | 4 | import Prelude 5 | import Effect.Console (log) 6 | import Bar (foo) 7 | 8 | baz :: Int 9 | baz = foo 10 | 11 | main = log "Done" 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ExplicitImportReExport/Bar.purs: -------------------------------------------------------------------------------- 1 | module Bar (module Foo) where 2 | 3 | import Foo 4 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ExplicitImportReExport/Foo.purs: -------------------------------------------------------------------------------- 1 | module Foo where 2 | 3 | foo :: Int 4 | foo = 3 5 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ExplicitOperatorSections.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | subtractOne :: Int -> Int 7 | subtractOne = (_ - 1) 8 | 9 | addOne :: Int -> Int 10 | addOne = (1 + _) 11 | 12 | named :: Int -> Int 13 | named = (_ `sub` 1) 14 | 15 | main = log "Done" 16 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ExportExplicit.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import M1 4 | import Effect.Console (log) 5 | 6 | testX = X 7 | testZ = Z 8 | testFoo = foo 9 | 10 | main = log "Done" 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ExportExplicit/M1.purs: -------------------------------------------------------------------------------- 1 | module M1 (X(X), Z(..), foo) where 2 | 3 | data X = X | Y 4 | data Z = Z 5 | 6 | foo :: Int 7 | foo = 0 8 | 9 | bar :: Int 10 | bar = 1 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ExportExplicit2.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import M1 4 | import Effect.Console (log) 5 | 6 | testBar = bar 7 | 8 | main = log "Done" 9 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ExportExplicit2/M1.purs: -------------------------------------------------------------------------------- 1 | module M1 (bar) where 2 | 3 | foo :: Int 4 | foo = 0 5 | 6 | bar :: Int 7 | bar = foo 8 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ExportedInstanceDeclarations.purs: -------------------------------------------------------------------------------- 1 | -- Tests that instances for non-exported classes / types do not appear in the 2 | -- result of `exportedDeclarations`. 3 | module Main 4 | ( Const(..) 5 | , class Foo 6 | , foo 7 | , main 8 | ) where 9 | 10 | import Prelude 11 | import Effect.Console (log) 12 | 13 | data Const a b = Const a 14 | 15 | class Foo a where 16 | foo :: a 17 | 18 | data NonexportedType = NonexportedType 19 | 20 | class NonexportedClass a where 21 | notExported :: a 22 | 23 | -- There are three places that a nonexported type or type class can occur, 24 | -- leading an instance to count as non-exported: 25 | -- * The instance types 26 | -- * Constraints 27 | -- * The type class itself 28 | 29 | -- Case 1: instance types 30 | instance constFoo :: Foo (Const NonexportedType b) where 31 | foo = Const NonexportedType 32 | else 33 | -- Case 2: constraints 34 | instance nonExportedFoo :: (Foo NonexportedType) => Foo (a -> a) where 35 | foo = identity 36 | else 37 | -- Another instance of case 2: 38 | instance nonExportedFoo2 :: (NonexportedClass a) => Foo a where 39 | foo = notExported 40 | 41 | -- Case 3: type class 42 | instance nonExportedNonexportedType :: NonexportedClass (Const Int a) where 43 | notExported = Const 0 44 | 45 | main = log "Done" 46 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ExtendedInfixOperators.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log, logShow) 5 | import Data.Function (on) 6 | 7 | comparing :: forall a b. Ord b => (a -> b) -> a -> a -> Ordering 8 | comparing f = compare `on` f 9 | 10 | null [] = true 11 | null _ = false 12 | 13 | test = [1.0, 2.0, 3.0] `comparing null` [4.0, 5.0, 6.0] 14 | 15 | main = do 16 | logShow test 17 | log "Done" 18 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Fib.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | import Control.Monad.ST as ST 6 | import Control.Monad.ST.Ref as STRef 7 | 8 | fib :: Number 9 | fib = ST.run do 10 | n1 <- STRef.new 1.0 11 | n2 <- STRef.new 1.0 12 | ST.while ((>) 1000.0 <$> STRef.read n1) do 13 | n1' <- STRef.read n1 14 | n2' <- STRef.read n2 15 | _ <- STRef.write (n1' + n2') n2 16 | STRef.write n2' n1 17 | STRef.read n2 18 | 19 | main = do 20 | log "Done" 21 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/FieldConsPuns.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log, logShow) 5 | 6 | greet { greeting, name } = log $ greeting <> ", " <> name <> "." 7 | 8 | main = do 9 | greet { greeting, name } 10 | log "Done" 11 | where 12 | greeting = "Hello" 13 | name = "World" 14 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/FieldPuns.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console 5 | 6 | greet { greeting, name } = log $ greeting <> ", " <> name <> "." 7 | 8 | main = do 9 | greet { greeting: "Hello", name: "World" } 10 | log "Done" 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/FinalTagless.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude hiding (add) 4 | import Effect.Console (log, logShow) 5 | 6 | class E e where 7 | num :: Number -> e Number 8 | add :: e Number -> e Number -> e Number 9 | 10 | type Expr a = forall e. E e => e a 11 | 12 | data Id a = Id a 13 | 14 | instance exprId :: E Id where 15 | num = Id 16 | add (Id n) (Id m) = Id (n + m) 17 | 18 | runId (Id a) = a 19 | 20 | three :: Expr Number 21 | three = add (num 1.0) (num 2.0) 22 | 23 | main = do 24 | logShow $ runId three 25 | log "Done" 26 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ForeignKind.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import ForeignKinds.Lib (kind Nat, Zero, Succ, N3, NatProxy, class AddNat, addNat, proxy1, proxy2) 5 | import Effect.Console (log) 6 | 7 | proxy1Add2Is3 :: NatProxy N3 8 | proxy1Add2Is3 = addNat proxy1 proxy2 9 | 10 | main = log "Done" 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ForeignKind/Lib.purs: -------------------------------------------------------------------------------- 1 | module ForeignKinds.Lib (kind Nat, Kinded, Zero, Succ, N0, N1, N2, N3, NatProxy(..), class AddNat, addNat, proxy1, proxy2) where 2 | 3 | -- declaration 4 | 5 | foreign import kind Nat 6 | 7 | -- use in foreign data 8 | 9 | foreign import data Zero :: Nat 10 | foreign import data Succ :: Nat -> Nat 11 | 12 | -- use in data 13 | 14 | data NatProxy (t :: Nat) = NatProxy 15 | 16 | -- use in type sig 17 | 18 | succProxy :: forall n. NatProxy n -> NatProxy (Succ n) 19 | succProxy _ = NatProxy 20 | 21 | -- use in alias 22 | 23 | type Kinded f = f :: Nat 24 | 25 | type KindedZero = Kinded Zero 26 | 27 | type N0 = Zero 28 | type N1 = Succ N0 29 | type N2 = Succ N1 30 | type N3 = Succ N2 31 | 32 | -- use of alias 33 | 34 | proxy0 :: NatProxy N0 35 | proxy0 = NatProxy 36 | 37 | proxy1 :: NatProxy N1 38 | proxy1 = NatProxy 39 | 40 | proxy2 :: NatProxy N2 41 | proxy2 = NatProxy 42 | 43 | proxy3 :: NatProxy N3 44 | proxy3 = NatProxy 45 | 46 | -- use in class 47 | 48 | class AddNat (l :: Nat) (r :: Nat) (o :: Nat) | l -> r o 49 | 50 | instance addNatZero 51 | :: AddNat Zero r r 52 | 53 | instance addNatSucc 54 | :: AddNat l r o 55 | => AddNat (Succ l) r (Succ o) 56 | 57 | -- use of class 58 | 59 | addNat :: forall l r o. AddNat l r o => NatProxy l -> NatProxy r -> NatProxy o 60 | addNat _ _ = NatProxy 61 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/FunWithFunDeps.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | PURS_FFI_VALUE(Main_fnil, PURS_ANY_ARRAY(NULL)); 4 | 5 | PURS_FFI_FUNC_2(Main_fcons, _head, _tail) { 6 | const purs_vec_t *vec = purs_vec_new_va(1, _head); 7 | purs_any_t ret = purs_any_concat(purs_any_array(vec), _tail); 8 | PURS_RC_RELEASE(vec); 9 | return ret; 10 | } 11 | 12 | PURS_FFI_FUNC_3(Main_fappend, _, _left, _right) { 13 | return purs_any_concat(_left, _right); 14 | } 15 | 16 | PURS_FFI_FUNC_2(Main_fflatten, _, _v) { 17 | const purs_vec_t *v = purs_any_force_array(_v); 18 | int i; 19 | purs_any_t tmp; 20 | purs_any_t o = purs_any_array(NULL); 21 | purs_vec_foreach(v, tmp, i) { 22 | o = purs_any_concat(o, tmp); 23 | } 24 | PURS_RC_RELEASE(v); 25 | return o; 26 | } 27 | 28 | PURS_FFI_FUNC_1(Main_ftoArray, x) { 29 | PURS_ANY_RETAIN(x); 30 | return x; 31 | } 32 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/FunWithFunDeps.h: -------------------------------------------------------------------------------- 1 | #ifndef Main_H 2 | #define Main_H 3 | 4 | #include 5 | 6 | PURS_FFI_EXPORT(Main_fnil); 7 | PURS_FFI_EXPORT(Main_fcons); 8 | PURS_FFI_EXPORT(Main_fappend); 9 | PURS_FFI_EXPORT(Main_fflatten); 10 | PURS_FFI_EXPORT(Main_ftoArray); 11 | 12 | #endif // Main_H 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/FunWithFunDeps.js: -------------------------------------------------------------------------------- 1 | 2 | //: forall e. FVect Z e 3 | exports.fnil = []; 4 | 5 | //: forall n e. e -> FVect n e -> FVect (S n) e 6 | exports.fcons = function (hd) { 7 | return function (tl) { 8 | return [hd].concat(tl); 9 | }; 10 | }; 11 | 12 | exports.fappend = function (dict) { 13 | return function (left) { 14 | return function (right) { 15 | return left.concat(right); 16 | }; 17 | }; 18 | }; 19 | 20 | exports.fflatten = function (dict) { 21 | return function (v) { 22 | var accRef = []; 23 | for (var indexRef = 0; indexRef < v.length; indexRef += 1) { 24 | accRef = accRef.concat(v[indexRef]); 25 | } 26 | return accRef; 27 | }; 28 | }; 29 | 30 | exports.ftoArray = function (vect) { 31 | return vect; 32 | }; 33 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/FunWithFunDeps.purs: -------------------------------------------------------------------------------- 1 | -- Taken from https://github.com/LiamGoodacre/purescript-fun-with-fundeps 2 | 3 | module Main where 4 | 5 | import Effect.Console (log) 6 | 7 | -- Nat : Type 8 | data Z 9 | data S n 10 | 11 | type S2 n = S (S n) 12 | type S3 n = S (S2 n) 13 | type S4 n = S (S3 n) 14 | type S5 n = S (S4 n) 15 | type S15 n = S5 (S5 (S5 n)) 16 | 17 | class NatPlus l r o | l r -> o 18 | instance natPlusZ :: NatPlus Z r r 19 | instance natPlusS :: (NatPlus l r o) => NatPlus (S l) r (S o) 20 | 21 | class NatMult l r o | l r -> o 22 | instance natMultZ :: NatMult Z n Z 23 | instance natMultS :: (NatMult m n r, NatPlus n r s) => NatMult (S m) n s 24 | 25 | -- Foreign Vect 26 | foreign import data FVect :: Type -> Type -> Type 27 | foreign import fnil :: forall e. FVect Z e 28 | foreign import fcons :: forall n e. e -> FVect n e -> FVect (S n) e 29 | foreign import fappend :: forall l r o e. NatPlus l r o => FVect l e -> FVect r e -> FVect o e 30 | foreign import fflatten :: forall f s t o. NatMult f s o => FVect f (FVect s t) -> FVect o t 31 | foreign import ftoArray :: forall n e. FVect n e -> Array e 32 | 33 | -- should be able to figure these out 34 | fsingleton x = fcons x fnil 35 | fexample = fcons 1 (fsingleton 2) `fappend` fsingleton 3 `fappend` fcons 4 (fsingleton 5) 36 | fexample2 = fexample `fappend` fexample `fappend` fexample 37 | fexample3 = fsingleton fexample `fappend` fsingleton fexample `fappend` fsingleton fexample 38 | 39 | fexample4 = fflatten fexample3 40 | 41 | main = log "Done" 42 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/FunctionScope.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Test.Assert 5 | import Effect.Console (log) 6 | 7 | mkValue :: Number -> Number 8 | mkValue id = id 9 | 10 | main = do 11 | let value = mkValue 1.0 12 | assert $ value == 1.0 13 | log "Done" 14 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/FunctionalDependencies.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | data Nil 6 | data Cons x xs 7 | 8 | class Append a b c | a b -> c 9 | 10 | instance appendNil :: Append Nil b b 11 | 12 | instance appendCons :: Append xs b c => Append (Cons x xs) b (Cons x c) 13 | 14 | data Proxy a = Proxy 15 | 16 | appendProxy :: forall a b c. Append a b c => Proxy a -> Proxy b -> Proxy c 17 | appendProxy Proxy Proxy = Proxy 18 | 19 | test = appendProxy (Proxy :: Proxy (Cons Int Nil)) (Proxy :: Proxy (Cons String Nil)) 20 | 21 | main = log "Done" 22 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Functions.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | test1 = \_ -> 0.0 7 | 8 | test2 = \a b -> a + b + 1.0 9 | 10 | test3 = \a -> a 11 | 12 | main = log "Done" 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Functions2.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Test.Assert 5 | import Effect.Console (log) 6 | 7 | test :: forall a b. a -> b -> a 8 | test = \const _ -> const 9 | 10 | main = do 11 | let value = test "Done" {} 12 | assert' "Not done" $ value == "Done" 13 | log "Done" 14 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Generalization1.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (logShow, log) 5 | 6 | main = do 7 | logShow (sum 1.0 2.0) 8 | logShow (sum 1 2) 9 | log "Done" 10 | 11 | sum x y = x + y 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/GenericsRep.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect (Effect) 5 | import Effect.Console (log, logShow) 6 | import Data.Generic.Rep (class Generic) 7 | import Data.Generic.Rep.Eq (genericEq) 8 | 9 | data X a = X a 10 | 11 | derive instance genericX :: Generic (X a) _ 12 | 13 | instance eqX :: Eq a => Eq (X a) where 14 | eq xs ys = genericEq xs ys 15 | 16 | data Y a = Y | Z a (Y a) 17 | 18 | derive instance genericY :: Generic (Y a) _ 19 | 20 | instance eqY :: Eq a => Eq (Y a) where 21 | eq xs ys = genericEq xs ys 22 | 23 | data Z 24 | 25 | derive instance genericZ :: Generic Z _ 26 | 27 | instance eqZ :: Eq Z where 28 | eq x y = genericEq x y 29 | 30 | type MyString = String 31 | 32 | newtype W = W { x :: Int, y :: MyString } 33 | 34 | derive instance genericW :: Generic W _ 35 | 36 | main :: Effect Unit 37 | main = do 38 | logShow (X 0 == X 1) 39 | logShow (X 1 == X 1) 40 | logShow (Z 1 Y == Z 1 Y) 41 | logShow (Z 1 Y == Y) 42 | logShow (Y == (Y :: Y Z)) 43 | log "Done" 44 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Guards.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | collatz = \x -> case x of 7 | y | y `mod` 2.0 == 0.0 -> y / 2.0 8 | y -> y * 3.0 + 1.0 9 | 10 | -- Guards have access to current scope 11 | collatz2 = \x y -> case x of 12 | z | y > 0.0 -> z / 2.0 13 | z -> z * 3.0 + 1.0 14 | 15 | min :: forall a. Ord a => a -> a -> a 16 | min n m | n < m = n 17 | | otherwise = m 18 | 19 | max :: forall a. Ord a => a -> a -> a 20 | max n m = case unit of 21 | _ | m < n -> n 22 | | otherwise -> m 23 | 24 | testIndentation :: Number -> Number -> Number 25 | testIndentation x y | x > 0.0 26 | = x + y 27 | | otherwise 28 | = y - x 29 | 30 | -- pattern guard example with two clauses 31 | clunky1 :: Int -> Int -> Int 32 | clunky1 a b | x <- max a b 33 | , x > 5 34 | = x 35 | clunky1 a _ = a 36 | 37 | clunky2 :: Int -> Int -> Int 38 | clunky2 a b | x <- max a b 39 | , x > 5 40 | = x 41 | | otherwise 42 | = a + b 43 | 44 | -- pattern guards on case epxressions 45 | clunky_case1 :: Int -> Int -> Int 46 | clunky_case1 a b = 47 | case unit of 48 | unit | x <- max a b 49 | , x > 5 50 | -> x 51 | | otherwise -> a + b 52 | 53 | -- test indentation 54 | clunky_case2 :: Int -> Int -> Int 55 | clunky_case2 a b = 56 | case unit of 57 | unit 58 | | x <- max a b 59 | , x > 5 60 | -> x 61 | | otherwise 62 | -> a + b 63 | 64 | main = log $ min "Done" "ZZZZ" 65 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/HasOwnProperty.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | main = log ({hasOwnProperty: "Hi"} {hasOwnProperty = "Done"}).hasOwnProperty 6 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/HoistError.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Effect.Console 6 | import Test.Assert 7 | 8 | main = do 9 | let x = 0.0 10 | assert $ x == 0.0 11 | let x = 1.0 + 1.0 12 | log "Done" 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/IfThenElseMaybe.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data Maybe a = Nothing | Just a 7 | 8 | test1 = if true then Just 10 else Nothing 9 | 10 | test2 = if true then Nothing else Just 10 11 | 12 | main = log "Done" 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/IfWildcard.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect (Effect) 5 | import Effect.Console (log) 6 | 7 | data Foo = X | Y 8 | 9 | cond ∷ ∀ a. Boolean → a → a → a 10 | cond = if _ then _ else _ 11 | 12 | what ∷ Boolean → Foo 13 | what = if _ then X else Y 14 | 15 | main :: Effect Unit 16 | main = do 17 | let tmp1 = what true 18 | tmp2 = cond true 0 1 19 | log "Done" 20 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ImplicitEmptyImport.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | main = do 7 | log "Hello" 8 | log "Goodbye" 9 | log "Done" 10 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ImportExplicit.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import M1 (X(..)) 4 | import Effect.Console (log) 5 | 6 | testX :: X 7 | testX = X 8 | testY = Y 9 | 10 | main = log "Done" 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ImportExplicit/M1.purs: -------------------------------------------------------------------------------- 1 | module M1 where 2 | 3 | data X = X | Y 4 | data Z = Z 5 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ImportHiding.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console 4 | import Prelude hiding ( 5 | show, -- a value 6 | class Show, -- a type class 7 | Unit(..) -- a constructor 8 | ) 9 | 10 | show = 1.0 11 | 12 | class Show a where 13 | noshow :: a -> a 14 | 15 | data Unit = X | Y 16 | 17 | main = do 18 | logShow show 19 | log "Done" 20 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ImportQualified.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import M1 6 | import Effect.Console as C 7 | 8 | main = C.log (log "Done") 9 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ImportQualified/M1.purs: -------------------------------------------------------------------------------- 1 | module M1 where 2 | 3 | log x = x 4 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/InferRecFunWithConstrainedArgument.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log, logShow) 5 | 6 | test 100 = 100 7 | test n = test(1 + n) 8 | 9 | main = do 10 | logShow (test 0) 11 | log "Done" 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/InstanceBeforeClass.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | instance fooNumber :: Foo Number where 7 | foo = 0.0 8 | 9 | class Foo a where 10 | foo :: a 11 | 12 | main = log "Done" 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/InstanceSigs.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | class Foo a where 6 | foo :: a 7 | 8 | instance fooNumber :: Foo Number where 9 | foo :: Number 10 | foo = 0.0 11 | 12 | main = log "Done" 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/InstanceSigsGeneral.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | class Eq a where 6 | eq :: a -> a -> Boolean 7 | 8 | instance eqNumber :: Eq Number where 9 | eq :: forall x y. x -> y -> Boolean 10 | eq _ _ = true 11 | 12 | main = log "Done" 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/IntAndChar.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Effect.Console (log) 6 | import Test.Assert 7 | 8 | f 1 = 1 9 | f _ = 0 10 | 11 | g 'a' = 'a' 12 | g _ = 'b' 13 | 14 | main = do 15 | assert $ f 1 == 1 16 | assert $ f 0 == 0 17 | assert $ g 'a' == 'a' 18 | assert $ g 'b' == 'b' 19 | log "Done" 20 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/JSReserved.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | yield = 0 7 | member = 1 8 | 9 | public = \return -> return 10 | 11 | this catch = catch 12 | 13 | main = log "Done" 14 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/KindedType.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | type Star2Star f = f :: Type -> Type 7 | 8 | type Star t = t :: Type 9 | 10 | test1 :: Star2Star Array String 11 | test1 = ["test"] 12 | 13 | f :: Star (String -> String) 14 | f s = s 15 | 16 | test2 = f "test" 17 | 18 | data Proxy (f :: Type -> Type) = Proxy 19 | 20 | test3 :: Proxy Array 21 | test3 = Proxy 22 | 23 | type Test (f :: Type -> Type) = f String 24 | 25 | test4 :: Test Array 26 | test4 = ["test"] 27 | 28 | class Clazz (a :: Type) where 29 | def :: a 30 | 31 | instance clazzString :: Clazz String where 32 | def = "test" 33 | 34 | main = log "Done" 35 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/LargeSumType.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | data Large = A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z 6 | 7 | explode A A = "A" 8 | explode B B = "B" 9 | explode C C = "C" 10 | explode D D = "D" 11 | explode E E = "E" 12 | explode F F = "F" 13 | explode G G = "G" 14 | explode H H = "H" 15 | explode I I = "I" 16 | explode J J = "J" 17 | explode K K = "K" 18 | explode L L = "L" 19 | explode M M = "M" 20 | explode N N = "N" 21 | explode O O = "O" 22 | explode P P = "P" 23 | explode Q Q = "Q" 24 | explode R R = "R" 25 | explode S S = "S" 26 | explode T T = "T" 27 | explode U U = "U" 28 | explode V V = "V" 29 | explode W W = "W" 30 | explode X X = "X" 31 | explode Y Y = "Y" 32 | explode Z Z = "Z" 33 | explode _ _ = "" 34 | 35 | main = log "Done" 36 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Let.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Partial.Unsafe (unsafePartial) 5 | import Effect 6 | import Effect.Console (log, logShow) 7 | import Control.Monad.ST 8 | 9 | test1 x = let 10 | y :: Number 11 | y = x + 1.0 12 | in y 13 | 14 | test2 x y = 15 | let x' = x + 1.0 in 16 | let y' = y + 1.0 in 17 | x' + y' 18 | 19 | test3 = let f x y z = x + y + z in 20 | f 1.0 2.0 3.0 21 | 22 | test4 = let 23 | f x [y, z] = x y z 24 | in f (+) [1.0, 2.0] 25 | 26 | test5 = let 27 | f x | x > 0.0 = g (x / 2.0) + 1.0 28 | f x = 0.0 29 | g x = f (x - 1.0) + 1.0 30 | in f 10.0 31 | 32 | test7 = let 33 | f :: forall a. a -> a 34 | f x = x 35 | in if f true then f 1.0 else f 2.0 36 | 37 | test8 :: Number -> Number 38 | test8 x = let 39 | go y | (x - 0.1 < y * y) && (y * y < x + 0.1) = y 40 | go y = go $ (y + x / y) / 2.0 41 | in go x 42 | 43 | test10 _ = 44 | let 45 | f x = g x * 3.0 46 | g x = f x / 2.0 47 | in f 10.0 48 | 49 | main :: Effect _ 50 | main = do 51 | logShow (test1 1.0) 52 | logShow (test2 1.0 2.0) 53 | logShow test3 54 | unsafePartial (logShow test4) 55 | logShow test5 56 | logShow test7 57 | logShow (test8 100.0) 58 | log "Done" 59 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Let2.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log, logShow) 5 | 6 | test = 7 | let f :: Number -> Boolean 8 | f 0.0 = false 9 | f n = g (n - 1.0) 10 | 11 | g :: Number -> Boolean 12 | g 0.0 = true 13 | g n = f (n - 1.0) 14 | 15 | x = f 1.0 16 | in not x 17 | 18 | main = do 19 | logShow test 20 | log "Done" 21 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/LetInInstance.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | class Foo a where 7 | foo :: a -> String 8 | 9 | instance fooString :: Foo String where 10 | foo = go 11 | where 12 | go :: String -> String 13 | go s = s 14 | 15 | main = log "Done" 16 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/LiberalTypeSynonyms.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | type Reader = (->) String 7 | 8 | foo :: Reader String 9 | foo s = s 10 | 11 | type AndFoo r = (foo :: String | r) 12 | 13 | getFoo :: forall r. Prim.Record (AndFoo r) -> String 14 | getFoo o = o.foo 15 | 16 | type F r = { | r } -> { | r } 17 | 18 | f :: (forall r. F r) -> String 19 | f g = case g { x: "Hello" } of 20 | { x: x } -> x 21 | 22 | main = log "Done" 23 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/MPTCs.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | class NullaryTypeClass where 7 | greeting :: String 8 | 9 | instance nullaryTypeClass :: NullaryTypeClass where 10 | greeting = "Hello, World!" 11 | 12 | class Coerce a b where 13 | coerce :: a -> b 14 | 15 | instance coerceShow :: Show a => Coerce a String where 16 | coerce = show 17 | else 18 | instance coerceRefl :: Coerce a a where 19 | coerce a = a 20 | 21 | main = log "Done" 22 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Match.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data Foo a = Foo 7 | 8 | foo = \f -> case f of Foo -> "foo" 9 | 10 | main = log "Done" 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Module.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import M1 4 | import M2 5 | import Effect.Console (log) 6 | 7 | main = log "Done" 8 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Module/M1.purs: -------------------------------------------------------------------------------- 1 | module M1 where 2 | 3 | import Prelude 4 | 5 | data Foo = Foo String 6 | 7 | foo :: Foo -> String 8 | foo = \f -> case f of Foo s -> s <> "foo" 9 | 10 | bar :: Foo -> String 11 | bar = foo 12 | 13 | incr :: Int -> Int 14 | incr x = x + 1 15 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Module/M2.purs: -------------------------------------------------------------------------------- 1 | module M2 where 2 | 3 | import Prelude 4 | import M1 as M1 5 | 6 | baz :: M1.Foo -> String 7 | baz = M1.foo 8 | 9 | match :: M1.Foo -> String 10 | match = \f -> case f of M1.Foo s -> s <> "foo" 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ModuleDeps.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import M1 4 | import Effect.Console (log) 5 | 6 | main = log "Done" 7 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ModuleDeps/M1.purs: -------------------------------------------------------------------------------- 1 | module M1 where 2 | 3 | import M2 as M2 4 | 5 | foo = M2.bar 6 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ModuleDeps/M2.purs: -------------------------------------------------------------------------------- 1 | module M2 where 2 | 3 | import M3 as M3 4 | 5 | bar = M3.baz 6 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ModuleDeps/M3.purs: -------------------------------------------------------------------------------- 1 | module M3 where 2 | 3 | baz = 1 4 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ModuleExport.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log, logShow) 4 | import A 5 | 6 | main = do 7 | logShow (show 1.0) 8 | log "Done" 9 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ModuleExport/A.purs: -------------------------------------------------------------------------------- 1 | module A (module Prelude) where 2 | 3 | import Prelude 4 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ModuleExportDupes.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console 4 | import A 5 | import B 6 | import C 7 | import Prelude 8 | 9 | main = do 10 | logShow (show 1.0) 11 | log "Done" 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ModuleExportDupes/A.purs: -------------------------------------------------------------------------------- 1 | module A (module Prelude) where 2 | 3 | import Prelude 4 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ModuleExportDupes/B.purs: -------------------------------------------------------------------------------- 1 | module B (module Prelude) where 2 | 3 | import Prelude 4 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ModuleExportDupes/C.purs: -------------------------------------------------------------------------------- 1 | module C (module Prelude, module A) where 2 | 3 | import Prelude 4 | import A 5 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ModuleExportExcluded.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log, logShow) 5 | import A (foo) 6 | 7 | otherwise = false 8 | 9 | main = do 10 | logShow "1.0" 11 | log "Done" 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ModuleExportExcluded/A.purs: -------------------------------------------------------------------------------- 1 | module A (module Prelude, foo) where 2 | 3 | import Prelude 4 | 5 | foo :: Number -> Number 6 | foo _ = 0.0 7 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ModuleExportQualified.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log, logShow) 5 | import A as B 6 | 7 | main = do 8 | logShow (B.show 1.0) 9 | log "Done" 10 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ModuleExportQualified/A.purs: -------------------------------------------------------------------------------- 1 | module A (module Prelude) where 2 | 3 | import Prelude 4 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ModuleExportSelf.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console 4 | import A 5 | 6 | bar :: Foo 7 | bar = true 8 | 9 | main = do 10 | logShow (show bar) 11 | log "Done" 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ModuleExportSelf/A.purs: -------------------------------------------------------------------------------- 1 | module A (module A, module Prelude) where 2 | 3 | import Prelude 4 | 5 | type Foo = Boolean 6 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Monad.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | type Monad m = { return :: forall a. a -> m a 6 | , bind :: forall a b. m a -> (a -> m b) -> m b } 7 | 8 | data Id a = Id a 9 | 10 | id :: Monad Id 11 | id = { return : Id 12 | , bind : \ma f -> case ma of Id a -> f a } 13 | 14 | data Maybe a = Nothing | Just a 15 | 16 | maybe :: Monad Maybe 17 | maybe = { return : Just 18 | , bind : \ma f -> case ma of 19 | Nothing -> Nothing 20 | Just a -> f a 21 | } 22 | 23 | test :: forall m. Monad m -> m Number 24 | test = \m -> m.bind (m.return 1.0) (\n1 -> 25 | m.bind (m.return "Test") (\n2 -> 26 | m.return n1)) 27 | 28 | test1 = test id 29 | 30 | test2 = test maybe 31 | 32 | main = log "Done" 33 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/MonadState.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console 5 | 6 | data Tuple a b = Tuple a b 7 | 8 | instance showTuple :: (Show a, Show b) => Show (Tuple a b) where 9 | show (Tuple a b) = "(" <> show a <> ", " <> show b <> ")" 10 | 11 | class Monad m <= MonadState s m where 12 | get :: m s 13 | put :: s -> m Unit 14 | 15 | data State s a = State (s -> Tuple s a) 16 | 17 | runState s (State f) = f s 18 | 19 | instance functorState :: Functor (State s) where 20 | map = liftM1 21 | 22 | instance applyState :: Apply (State s) where 23 | apply = ap 24 | 25 | instance applicativeState :: Applicative (State s) where 26 | pure a = State $ \s -> Tuple s a 27 | 28 | instance bindState :: Bind (State s) where 29 | bind f g = State $ \s -> case runState s f of 30 | Tuple s1 a -> runState s1 (g a) 31 | 32 | instance monadState :: Monad (State s) 33 | 34 | instance monadStateState :: MonadState s (State s) where 35 | get = State (\s -> Tuple s s) 36 | put s = State (\_ -> Tuple s unit) 37 | 38 | -- Without the call to same, the following strange (but correct, in the absence of 39 | -- functional dependencies) type: 40 | -- 41 | -- forall m t1 t2. 42 | -- ( Bind m 43 | -- , MonadState t1 m 44 | -- , MonadState t2 m 45 | -- ) => (t1 -> t2) -> m Unit 46 | -- 47 | -- With the type hint, the inferred type is more sensible: 48 | -- 49 | -- forall m t. 50 | -- ( Bind m 51 | -- , MonadState t m 52 | -- ) => (t -> t) -> m Unit 53 | modify f = 54 | do 55 | s <- get 56 | put (same f s) 57 | where 58 | same :: forall a. (a -> a) -> (a -> a) 59 | same = identity 60 | 61 | main = do 62 | logShow $ runState 0 (modify (_ + 1)) 63 | log "Done" 64 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/MultiArgFunctions.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Data.Function.Uncurried 5 | import Effect 6 | import Effect.Console 7 | 8 | f = mkFn2 $ \a b -> runFn2 g a b + runFn2 g b a 9 | 10 | g = mkFn2 $ \a b -> case {} of 11 | _ | a <= 0.0 || b <= 0.0 -> b 12 | _ -> runFn2 f (a - 0.0) (b - 0.0) 13 | 14 | main = do 15 | runFn0 (mkFn0 $ \_ -> log $ show 0.0) 16 | runFn1 (mkFn1 $ \a -> log $ show a) 0.0 17 | runFn2 (mkFn2 $ \a b -> log $ show [a, b]) 0.0 0.0 18 | runFn3 (mkFn3 $ \a b c -> log $ show [a, b, c]) 0.0 0.0 0.0 19 | runFn4 (mkFn4 $ \a b c d -> log $ show [a, b, c, d]) 0.0 0.0 0.0 0.0 20 | runFn5 (mkFn5 $ \a b c d e -> log $ show [a, b, c, d, e]) 0.0 0.0 0.0 0.0 0.0 21 | runFn6 (mkFn6 $ \a b c d e f -> log $ show [a, b, c, d, e, f]) 0.0 0.0 0.0 0.0 0.0 0.0 22 | runFn7 (mkFn7 $ \a b c d e f g -> log $ show [a, b, c, d, e, f, g]) 0.0 0.0 0.0 0.0 0.0 0.0 0.0 23 | runFn8 (mkFn8 $ \a b c d e f g h -> log $ show [a, b, c, d, e, f, g, h]) 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 24 | runFn9 (mkFn9 $ \a b c d e f g h i -> log $ show [a, b, c, d, e, f, g, h, i]) 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 25 | runFn10 (mkFn10 $ \a b c d e f g h i j-> log $ show [a, b, c, d, e, f, g, h, i, j]) 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 26 | logShow $ runFn2 g 0.0 0.0 27 | log "Done" 28 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/MutRec.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | f 0.0 = 0.0 7 | f x = g x + 0.0 8 | 9 | g x = f (x / 0.0) 10 | 11 | data Even = Zero | Even Odd 12 | 13 | data Odd = Odd Even 14 | 15 | evenToNumber Zero = 0.0 16 | evenToNumber (Even n) = oddToNumber n + 0.0 17 | 18 | oddToNumber (Odd n) = evenToNumber n + 0.0 19 | 20 | main = log "Done" 21 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/MutRec2.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data A = A B 7 | 8 | data B = B A 9 | 10 | foreign import data S :: Type 11 | 12 | f :: A -> S 13 | f a = case a of A b -> g b 14 | 15 | g b = case b of B a -> f a 16 | 17 | showN :: A -> S 18 | showN a = f a 19 | 20 | main = log "Done" 21 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/MutRec3.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data A = A B 7 | 8 | data B = B A 9 | 10 | foreign import data S :: Type 11 | 12 | f a = case a of A b -> g b 13 | 14 | g :: B -> S 15 | g b = case b of B a -> f a 16 | 17 | showN :: A -> S 18 | showN a = f a 19 | 20 | main = log "Done" 21 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/NakedConstraint.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console 4 | 5 | data List a = Nil | Cons a (List a) 6 | 7 | head :: Partial => List Int -> Int 8 | head (Cons x _) = x 9 | 10 | main = log "Done" 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/NamedPatterns.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | foo = \x -> case x of 7 | y@{ foo: "Foo" } -> y 8 | y -> y 9 | 10 | main = log "Done" 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/NegativeBinder.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | test :: Number -> Boolean 7 | test -1.0 = false 8 | test _ = true 9 | 10 | main = log "Done" 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/NegativeIntInRange.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | n :: Int 7 | n = -2147483648 8 | 9 | main = log "Done" 10 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Nested.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data Extend r a = Extend { prev :: r a, next :: a } 7 | 8 | data Matrix r a = Square (r (r a)) | Bigger (Matrix (Extend r) a) 9 | 10 | main = log "Done" 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/NestedRecordUpdate.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console 5 | 6 | type T = { foo :: Int, bar :: { baz :: Int, qux :: { lhs :: Int, rhs :: Int } } } 7 | 8 | init :: T 9 | init = { foo: 1, bar: { baz: 2, qux: { lhs: 3, rhs: 4 } } } 10 | 11 | updated :: T 12 | updated = init { foo = 10, bar { baz = 20, qux { lhs = 30, rhs = 40 } } } 13 | 14 | expected :: T 15 | expected = { foo: 10, bar: { baz: 20, qux: { lhs: 30, rhs: 40 } } } 16 | 17 | check l r = 18 | l.foo == r.foo && 19 | l.bar.baz == r.bar.baz && 20 | l.bar.qux.lhs == r.bar.qux.lhs && 21 | l.bar.qux.rhs == r.bar.qux.rhs 22 | 23 | main = do 24 | when (check updated expected) $ log "Done" 25 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/NestedRecordUpdateWildcards.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console 5 | 6 | update = _ { foo = _, bar { baz = _, qux = _ } } 7 | 8 | init = { foo: 1, bar: { baz: 2, qux: 3 } } 9 | 10 | after = update init 10 20 30 11 | 12 | expected = { foo: 10, bar: { baz: 20, qux: 30 } } 13 | 14 | check l r = 15 | l.foo == r.foo && 16 | l.bar.baz == r.bar.baz && 17 | l.bar.qux == r.bar.qux 18 | 19 | main = do 20 | when (check after expected) $ log "Done" 21 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/NestedTypeSynonyms.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | type X = String 7 | type Y = X -> X 8 | 9 | fn :: Y 10 | fn a = a 11 | 12 | main = log (fn "Done") 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/NestedWhere.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | f x = g x 7 | where 8 | g x = go x 9 | where 10 | go x = go1 (x - 1.0) 11 | go1 x = go x 12 | 13 | main = log "Done" 14 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/NewConsClass.purs: -------------------------------------------------------------------------------- 1 | -- This test verifies that we can write a new type class `Cons` without errors 2 | -- in the presence of the `Cons` class from `Prim.Row`. 3 | module Main where 4 | 5 | import Effect.Console (log) 6 | import Prim.Row(class Union) 7 | 8 | class Cons x xs | xs -> x where 9 | cons :: x -> xs -> xs 10 | 11 | 12 | main = log "Done" 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Newtype.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude hiding (apply) 4 | import Effect 5 | import Effect.Console 6 | 7 | newtype Thing = Thing String 8 | 9 | instance showThing :: Show Thing where 10 | show (Thing x) = "Thing " <> show x 11 | 12 | newtype Box a = Box a 13 | 14 | instance showBox :: (Show a) => Show (Box a) where 15 | show (Box x) = "Box " <> show x 16 | 17 | apply f x = f x 18 | 19 | main = do 20 | logShow $ Thing "hello" 21 | logShow $ Box 42.0 22 | logShow $ apply Box 9000.0 23 | log "Done" 24 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/NewtypeClass.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Effect.Console 6 | 7 | class Newtype t a | t -> a where 8 | wrap :: a -> t 9 | unwrap :: t -> a 10 | 11 | instance newtypeMultiplicative :: Newtype (Multiplicative a) a where 12 | wrap = Multiplicative 13 | unwrap (Multiplicative a) = a 14 | 15 | data Multiplicative a = Multiplicative a 16 | 17 | instance semiringMultiplicative :: Semiring a => Semigroup (Multiplicative a) where 18 | append (Multiplicative a) (Multiplicative b) = Multiplicative (a * b) 19 | 20 | data Pair a = Pair a a 21 | 22 | foldPair :: forall a s. Semigroup s => (a -> s) -> Pair a -> s 23 | foldPair f (Pair a b) = f a <> f b 24 | 25 | ala 26 | :: forall f t a 27 | . Functor f 28 | => Newtype t a 29 | => (a -> t) 30 | -> ((a -> t) -> f t) 31 | -> f a 32 | ala _ f = map unwrap (f wrap) 33 | 34 | test = ala Multiplicative foldPair 35 | 36 | test1 = ala Multiplicative foldPair (Pair 2 3) 37 | 38 | main = do 39 | logShow (test (Pair 2 3)) 40 | log "Done" 41 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/NewtypeEff.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console 5 | import Effect 6 | 7 | newtype T a = T (Effect a) 8 | 9 | runT :: forall a. T a -> Effect a 10 | runT (T t) = t 11 | 12 | instance functorT :: Functor T where 13 | map f (T t) = T (f <$> t) 14 | 15 | instance applyT :: Apply T where 16 | apply (T f) (T x) = T (f <*> x) 17 | 18 | instance applicativeT :: Applicative T where 19 | pure t = T (pure t) 20 | 21 | instance bindT :: Bind T where 22 | bind (T t) f = T (t >>= \x -> runT (f x)) 23 | 24 | instance monadT :: Monad T 25 | 26 | main = runT do 27 | T $ log "Done" 28 | T $ log "Done" 29 | T $ log "Done" 30 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/NewtypeWithRecordUpdate.purs: -------------------------------------------------------------------------------- 1 | -- https://github.com/purescript/purescript/issues/812.0 2 | 3 | module Main where 4 | 5 | import Prelude 6 | import Effect.Console 7 | 8 | newtype NewType a = NewType (Record a) 9 | 10 | rec1 :: Record (a :: Number, b :: Number, c:: Number) 11 | rec1 = { a: 0.0, b: 0.0, c: 0.0 } 12 | 13 | rec2 :: NewType (a :: Number, b :: Number, c :: Number) 14 | rec2 = NewType (rec1 { a = 1.0 }) 15 | 16 | main = log "Done" 17 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/NonConflictingExports.purs: -------------------------------------------------------------------------------- 1 | -- No failure here as the export `thing` only refers to Main.thing 2 | module Main (thing, main) where 3 | 4 | import A 5 | import Effect.Console (log) 6 | 7 | thing :: Int 8 | thing = 2 9 | 10 | main = log "Done" 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/NonConflictingExports/A.purs: -------------------------------------------------------------------------------- 1 | module A where 2 | 3 | thing :: Int 4 | thing = 1 5 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/NonOrphanInstanceFunDepExtra.purs: -------------------------------------------------------------------------------- 1 | -- Both f and l must be known, thus can be in separate modules 2 | module Main where 3 | import Effect.Console (log) 4 | import Lib 5 | data F 6 | data R 7 | instance cflr :: C F L R 8 | main = log "Done" 9 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/NonOrphanInstanceFunDepExtra/Lib.purs: -------------------------------------------------------------------------------- 1 | module Lib where 2 | -- covering sets: {{f, l}} 3 | class C f l r | l -> r 4 | data L 5 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/NonOrphanInstanceMulti.purs: -------------------------------------------------------------------------------- 1 | -- Both l and r must be known, thus can be in separate modules 2 | module Main where 3 | import Effect.Console (log) 4 | import Lib 5 | data L 6 | instance clr :: C L R 7 | main = log "Done" 8 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/NonOrphanInstanceMulti/Lib.purs: -------------------------------------------------------------------------------- 1 | module Lib where 2 | -- covering sets: {{l, r}} 3 | class C l r 4 | data R 5 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/NumberLiterals.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | -- See issue #2115. 4 | 5 | import Prelude 6 | import Test.Assert (assert') 7 | import Effect.Console (log) 8 | 9 | main = do 10 | test "0.17" 0.17 11 | test "0.25996181067141905" 0.25996181067141905 12 | test "0.3572019862807257" 0.3572019862807257 13 | test "0.46817723004874223" 0.46817723004874223 14 | test "0.9640035681058178" 0.9640035681058178 15 | test "4.23808622486133" 4.23808622486133 16 | test "4.540362294799751" 4.540362294799751 17 | test "5.212384849884261" 5.212384849884261 18 | test "13.958257048123212" 13.958257048123212 19 | test "32.96176575630599" 32.96176575630599 20 | test "38.47735512322269" 38.47735512322269 21 | 22 | test "10000000000.0" 1e10 23 | test "10000000000.0" 1.0e10 24 | test "0.00001" 1e-5 25 | test "0.00001" 1.0e-5 26 | test "1.5339794352098402e-118" 1.5339794352098402e-118 27 | test "2.108934760892056e-59" 2.108934760892056e-59 28 | test "2.250634744599241e-19" 2.250634744599241e-19 29 | test "5.960464477539063e-8" 5.960464477539063e-8 30 | test "5e-324" 5e-324 31 | test "5e-324" 5.0e-324 32 | 33 | log "Done" 34 | 35 | test str num = 36 | if (show num == str) 37 | then pure unit 38 | else flip assert' false $ 39 | "Expected " <> show str <> ", got " <> show (show num) <> "." 40 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ObjectGetter.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log, logShow) 5 | 6 | getX = _.x 7 | 8 | point = { x: 1.0, y: 0.0 } 9 | 10 | main = do 11 | logShow $ getX point 12 | log $ _." 123 string Prop Name " { " 123 string Prop Name ": "OK" } 13 | log $ (_.x >>> _.y) { x: { y: "Nested" } } 14 | log $ _.value { value: "Done" } 15 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ObjectSynonym.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | type Inner = Number 7 | 8 | inner :: Inner 9 | inner = 0.0 10 | 11 | type Outer = { inner :: Inner } 12 | 13 | outer :: Outer 14 | outer = { inner: inner } 15 | 16 | main = log "Done" 17 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ObjectUpdate.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | update1 = \o -> o { foo = "Foo" } 7 | 8 | update2 :: forall r. { foo :: String | r } -> { foo :: String | r } 9 | update2 = \o -> o { foo = "Foo" } 10 | 11 | replace = \o -> case o of 12 | { foo: "Foo" } -> o { foo = "Bar" } 13 | { foo: "Bar" } -> o { bar = "Baz" } 14 | o -> o 15 | 16 | polyUpdate :: forall a r. { foo :: a | r } -> { foo :: String | r } 17 | polyUpdate = \o -> o { foo = "Foo" } 18 | 19 | inferPolyUpdate = \o -> o { foo = "Foo" } 20 | 21 | main = do 22 | log ((update1 {foo: ""}).foo) 23 | log "Done" 24 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ObjectUpdate2.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | type X r = { | r } 7 | 8 | x :: X (baz :: String) 9 | x = { baz: "baz" } 10 | 11 | blah :: forall r. X r -> X r 12 | blah x = x 13 | 14 | test = blah x 15 | { baz = "blah" 16 | } 17 | 18 | main = log "Done" 19 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ObjectUpdater.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Effect.Console 6 | import Test.Assert 7 | 8 | getValue :: Effect Boolean 9 | getValue = pure true 10 | 11 | main = do 12 | let record = { value: false } 13 | record' <- record { value = _ } <$> getValue 14 | assert $ record'.value == true 15 | 16 | let point = { x: 1.0, y: 1.0 } 17 | x = 10.0 18 | point' = (point { x = _, y = x }) 100.0 19 | 20 | assert $ point'.x == 100.0 21 | assert $ point'.y == 10.0 22 | 23 | let record2 = (_ { x = _ }) { x: 0.0 } 10.0 24 | assert $ record2.x == 10.0 25 | 26 | log "Done" 27 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ObjectWildcards.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Effect.Console 6 | import Test.Assert 7 | 8 | mkRecord = { foo: _, bar: _, baz: "baz" } 9 | 10 | getValue :: Effect Boolean 11 | getValue = pure true 12 | 13 | main = do 14 | obj <- { value: _ } <$> getValue 15 | logShow obj.value 16 | let x = 1.0 17 | point <- { x: _, y: x } <$> pure 2.0 18 | assert $ point.x == 2.0 19 | assert $ point.y == 1.0 20 | log (mkRecord 1.0 "Done").bar 21 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Objects.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude hiding (append) 4 | import Effect.Console (log) 5 | 6 | test = \x -> x.foo + x.bar + 1.0 7 | 8 | append = \o -> { foo: o.foo, bar: 1.0 } 9 | 10 | apTest = append({foo : "Foo", baz: "Baz"}) 11 | 12 | f = (\a -> a.b.c) { b: { c: 1.0, d: "Hello" }, e: "World" } 13 | 14 | g = (\a -> a.f { x: 1.0, y: "y" }) { f: \o -> o.x + 1.0 } 15 | 16 | typed :: { foo :: Number } 17 | typed = { foo: 0.0 } 18 | 19 | test2 = \x -> x."!@#" 20 | 21 | test3 = typed."foo" 22 | 23 | test4 = test2 weirdObj 24 | where 25 | weirdObj :: { "!@#" :: Number } 26 | weirdObj = { "!@#": 1.0 } 27 | 28 | test5 = case { "***": 1.0 } of 29 | { "***": n } -> n 30 | 31 | test6 = case { "***": 1.0 } of 32 | { "***": n } -> n 33 | 34 | test7 {a: snoog , b : blah } = blah 35 | 36 | main = log "Done" 37 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/OneConstructor.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data One a = One a 7 | 8 | one' (One a) = a 9 | 10 | main = log "Done" 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/OperatorAlias.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console 5 | 6 | infixl 4 what as ?! 7 | 8 | what :: forall a b. a -> b -> a 9 | what a _ = a 10 | 11 | main = log $ "Done" ?! true 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/OperatorAliasElsewhere.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Def (what) 5 | import Effect.Console 6 | 7 | infixl 4 what as ?! 8 | 9 | main = log $ "Done" ?! true 10 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/OperatorAliasElsewhere/Def.purs: -------------------------------------------------------------------------------- 1 | module Def where 2 | 3 | what :: forall a b. a -> b -> a 4 | what a _ = a 5 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/OperatorAssociativity.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Effect.Console 6 | import Test.Assert 7 | 8 | bug :: Number -> Number -> Number 9 | bug a b = 0.0 - (a - b) 10 | 11 | main = do 12 | assert (bug 0.0 2.0 == 2.0) 13 | assert (0.0 - (0.0 - 2.0) == 2.0) 14 | assert (0.0 - (0.0 + 2.0) == -2.0) 15 | assert (6.0 / (3.0 * 2.0) == 1.0) 16 | assert ((6.0 / 3.0) * 2.0 == 4.0) 17 | assert (not (1.0 < 0.0) == true) 18 | assert (not ((negate 1.0) < 0.0) == false) 19 | assert (negate (1.0 + 10.0) == -11.0) 20 | assert (2.0 * 3.0 / 4.0 == 1.5) 21 | assert (1.0 * 2.0 * 3.0 * 4.0 * 5.0 / 6.0 == 20.0) 22 | assert (1.0 + 10.0 - 5.0 == 6.0) 23 | assert (1.0 + 10.0 * 5.0 == 51.0) 24 | assert (10.0 * 5.0 - 1.0 == 49.0) 25 | log "Done" 26 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/OperatorInlining.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (logShow, log) 5 | 6 | main = do 7 | 8 | -- semiringNumber 9 | logShow (1.0 + 2.0) 10 | logShow (1.0 * 2.0) 11 | 12 | -- ringNumber 13 | logShow (1.0 - 2.0) 14 | logShow (negate 1.0) 15 | 16 | -- moduleSemiringNumber 17 | logShow (1.0 / 2.0) 18 | 19 | -- ordNumber 20 | logShow (1.0 > 2.0) 21 | logShow (1.0 < 2.0) 22 | logShow (1.0 <= 2.0) 23 | logShow (1.0 >= 2.0) 24 | logShow (1.0 == 2.0) 25 | 26 | -- eqNumber 27 | logShow (1.0 == 2.0) 28 | logShow (1.0 /= 2.0) 29 | 30 | -- eqString 31 | logShow ("foo" == "bar") 32 | logShow ("foo" /= "bar") 33 | 34 | -- eqBoolean 35 | logShow (true == false) 36 | logShow (true /= false) 37 | 38 | -- semigroupString 39 | logShow ("foo" <> "bar") 40 | 41 | -- latticeBoolean 42 | logShow (top && true) 43 | logShow (bottom || false) 44 | 45 | -- complementedLatticeBoolean 46 | logShow (not true) 47 | 48 | log "Done" 49 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/OperatorSections.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | import Test.Assert 6 | 7 | main = do 8 | assert $ (_ / 2.0) 4.0 == 2.0 9 | assert $ (2.0 / _) 4.0 == 0.5 10 | assert $ (_ `const` 1.0) 2.0 == 2.0 11 | assert $ (1.0 `const` _) 2.0 == 1.0 12 | let foo = { x: 2.0 } 13 | assert $ (_ / foo.x) 4.0 == 2.0 14 | assert $ (foo.x / _) 4.0 == 0.5 15 | let div x y = x.x / y.x 16 | assert $ (_ `div` foo { x = 4.0 }) { x: 4.0 } == 1.0 17 | assert $ (foo { x = 4.0 } `div` _) { x: 4.0 } == 1.0 18 | log "Done" 19 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Operators/Other.purs: -------------------------------------------------------------------------------- 1 | module Other where 2 | 3 | foo :: String -> String 4 | foo s = s 5 | 6 | baz :: String -> String -> String 7 | baz s _ = s 8 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/OptimizerBug.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | x a = 1.0 + y a 7 | 8 | y a = x a 9 | 10 | main = log "Done" 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/OptionalQualified.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude as P 4 | 5 | -- qualified import without the "qualified" keyword 6 | import Effect.Console as Console 7 | 8 | bind = P.bind 9 | 10 | main = do 11 | message <- P.pure "Done" 12 | Console.log message 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Ord1Deriving.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Data.Eq (class Eq1) 5 | import Data.Ord (class Ord1) 6 | import Effect.Console (log) 7 | 8 | data Product a b = Product a b 9 | 10 | derive instance eqMu :: (Eq a, Eq b) => Eq (Product a b) 11 | derive instance eq1Mu :: Eq a => Eq1 (Product a) 12 | 13 | derive instance ordMu :: (Ord a, Ord b) => Ord (Product a b) 14 | derive instance ord1Mu :: Ord a => Ord1 (Product a) 15 | 16 | main = log "Done" 17 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Ord1InOrdDeriving.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Data.Eq (class Eq1) 5 | import Data.Ord (class Ord1) 6 | import Effect.Console (log) 7 | 8 | newtype Mu f = In (f (Mu f)) 9 | 10 | derive instance eqMu :: Eq1 f => Eq (Mu f) 11 | derive instance ordMu :: Ord1 f => Ord (Mu f) 12 | 13 | main = log "Done" 14 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ParensInType.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect (Effect) 5 | import Effect.Console (log) 6 | 7 | class Foo a where 8 | foo :: (String -> a ((Unit))) 9 | 10 | instance fooLogEff :: Foo Effect where 11 | foo = log 12 | 13 | main :: Effect Unit 14 | main = foo "Done" 15 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ParensInTypedBinder.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect (Effect) 5 | import Effect.Console (log) 6 | 7 | foo :: Array Int 8 | foo = do 9 | xss :: Array (Array Int) <- [[[1,2,3], [4, 5]], [[6]]] 10 | xs :: Array Int <- xss 11 | xs 12 | 13 | main :: Effect Unit 14 | main = log "Done" 15 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/PartialFunction.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Effect.Console 6 | 7 | fn :: Partial => Number -> Number 8 | fn 0.0 = 0.0 9 | fn 1.0 = 2.0 10 | 11 | main = log "Done" 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Patterns.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | test = \x -> case x of 7 | { str: "Foo", bool: true } -> true 8 | { str: "Bar", bool: b } -> b 9 | _ -> false 10 | 11 | f = \o -> case o of 12 | { foo: "Foo" } -> o.bar 13 | _ -> 0 14 | 15 | h = \o -> case o of 16 | a@[_,_,_] -> a 17 | _ -> [] 18 | 19 | isDesc :: Array Number -> Boolean 20 | isDesc [x, y] | x > y = true 21 | isDesc _ = false 22 | 23 | main = log "Done" 24 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/PendingConflictingImports.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | -- No error as we never force `thing` to be resolved in `Main` 4 | import A 5 | import B 6 | import Effect.Console (log) 7 | 8 | main = log "Done" 9 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/PendingConflictingImports/A.purs: -------------------------------------------------------------------------------- 1 | module A where 2 | 3 | thing :: Int 4 | thing = 1 5 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/PendingConflictingImports/B.purs: -------------------------------------------------------------------------------- 1 | module B where 2 | 3 | thing :: Int 4 | thing = 2 5 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/PendingConflictingImports2.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import A 4 | import Effect.Console (log) 5 | 6 | -- No error as we never force `thing` to be resolved in `Main` 7 | thing :: Int 8 | thing = 2 9 | 10 | main = log "Done" 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/PendingConflictingImports2/A.purs: -------------------------------------------------------------------------------- 1 | module A where 2 | 3 | thing :: Int 4 | thing = 1 5 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Person.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data Person = Person { name :: String, age :: Number } 7 | 8 | showPerson :: Person -> String 9 | showPerson = \p -> case p of 10 | Person o -> o.name <> ", aged " <> show o.age 11 | 12 | main = log "Done" 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/PolyLabels.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | PURS_FFI_FUNC_2(Main_unsafeGet, _s, _o) { 4 | const purs_record_t *o = purs_any_force_record(_o); 5 | const purs_str_t *s = purs_any_force_string(_s); 6 | purs_any_t *v = purs_record_find_by_key(o, s); 7 | assert(v != NULL); 8 | PURS_ANY_RETAIN(*v); 9 | PURS_RC_RELEASE(o); 10 | PURS_RC_RELEASE(s); 11 | return *v; 12 | } 13 | 14 | PURS_FFI_FUNC_3(Main_unsafeSet, _s, _a, _o) { 15 | const purs_record_t *o = purs_any_force_record(_o); 16 | const purs_str_t *s = purs_any_force_string(_s); 17 | const purs_record_t *result = purs_record_add_multi(o, 1, s, _a); 18 | PURS_RC_RELEASE(o); 19 | PURS_RC_RELEASE(s); 20 | return purs_any_record(result); 21 | } 22 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/PolyLabels.h: -------------------------------------------------------------------------------- 1 | #ifndef Main_H 2 | #define Main_H 3 | 4 | #include 5 | 6 | PURS_FFI_EXPORT(Main_unsafeGet); 7 | PURS_FFI_EXPORT(Main_unsafeSet); 8 | 9 | #endif // Main_H 10 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/PolyLabels.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | exports.unsafeGet = function (s) { 4 | return function (o) { 5 | return o[s]; 6 | }; 7 | }; 8 | 9 | exports.unsafeSet = function(s) { 10 | return function(a) { 11 | return function (o) { 12 | var o1 = {}; 13 | o1[s] = a; 14 | return Object.assign({}, o, o1); 15 | }; 16 | }; 17 | }; 18 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/PolyLabels.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Prim.Row 5 | import Effect 6 | import Effect.Console 7 | import Data.Symbol (class IsSymbol, SProxy(..), reflectSymbol) 8 | 9 | foreign import unsafeGet 10 | :: forall r a 11 | . String 12 | -> Record r 13 | -> a 14 | 15 | foreign import unsafeSet 16 | :: forall r1 r2 a 17 | . String 18 | -> a 19 | -> Record r1 20 | -> Record r2 21 | 22 | get 23 | :: forall r r' l a 24 | . IsSymbol l 25 | => Cons l a r' r 26 | => SProxy l 27 | -> Record r 28 | -> a 29 | get l = unsafeGet (reflectSymbol l) 30 | 31 | set 32 | :: forall r1 r2 r l a b 33 | . IsSymbol l 34 | => Cons l a r r1 35 | => Cons l b r r2 36 | => SProxy l 37 | -> b 38 | -> Record r1 39 | -> Record r2 40 | set l = unsafeSet (reflectSymbol l) 41 | 42 | lens 43 | :: forall l f r1 r2 r a b 44 | . IsSymbol l 45 | => Cons l a r r1 46 | => Cons l b r r2 47 | => Functor f 48 | => SProxy l 49 | -> (a -> f b) 50 | -> Record r1 51 | -> f (Record r2) 52 | lens l f r = flip (set l) r <$> f (get l r) 53 | 54 | getFoo :: forall a r. { foo :: a | r } -> a 55 | getFoo = get (SProxy :: SProxy "foo") 56 | 57 | setFoo :: forall a b r. b -> { foo :: a | r } -> { foo :: b | r } 58 | setFoo = set (SProxy :: SProxy "foo") 59 | 60 | fooLens :: forall f a b r. Functor f => (a -> f b) -> { foo :: a | r } -> f { foo :: b | r } 61 | fooLens = lens (SProxy :: SProxy "foo") 62 | 63 | main :: Effect Unit 64 | main = do 65 | _ <- fooLens logShow { foo: 1 } 66 | log (getFoo (setFoo "Done" { foo: 1 })) 67 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/PrimedTypeName.purs: -------------------------------------------------------------------------------- 1 | module Main (T, T', T'', T''', main) where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data T a = T 7 | type T' = T Unit 8 | 9 | data T'' = TP 10 | 11 | foreign import data T''' ∷ Type 12 | 13 | instance eqT ∷ Eq T'' where 14 | eq _ _ = true 15 | 16 | type A' a b = b → a 17 | 18 | infixr 4 type A' as ↫ 19 | 20 | main = log "Done" 21 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/QualifiedNames.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Either as Either 5 | import Effect.Console (log) 6 | 7 | either :: forall a b c. (a -> c) -> (b -> c) -> Either.Either a b -> c 8 | either f _ (Either.Left x) = f x 9 | either _ g (Either.Right y) = g y 10 | 11 | main = log (either identity identity (Either.Left "Done")) 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/QualifiedNames/Either.purs: -------------------------------------------------------------------------------- 1 | module Either where 2 | 3 | import Prelude 4 | 5 | data Either a b = Left a | Right b 6 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/QualifiedQualifiedImports.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | -- qualified import with qualified imported names 4 | import Effect.Console (log) as Console 5 | 6 | main = Console.log "Done" 7 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Rank2Object.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console 5 | 6 | data Foo = Foo { id :: forall a. a -> a } 7 | 8 | foo :: Foo -> Number 9 | foo (Foo { id: f }) = f 0.0 10 | 11 | main = log "Done" 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Rank2TypeSynonym.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log, logShow) 5 | 6 | type Foo a = forall f. Monad f => f a 7 | 8 | foo :: forall a. a -> Foo a 9 | foo x = pure x 10 | 11 | bar :: Foo Number 12 | bar = foo 3.0 13 | 14 | main = do 15 | x <- bar 16 | logShow x 17 | log "Done" 18 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Rank2Types.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | test1 :: (forall a. (a -> a)) -> Number 7 | test1 = \f -> f 0.0 8 | 9 | forever :: forall m a b. (forall a b. m a -> (a -> m b) -> m b) -> m a -> m b 10 | forever = \bind action -> bind action $ \_ -> forever bind action 11 | 12 | main = log "Done" 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ReExportQualified.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import C 5 | import Effect.Console (log) 6 | 7 | main = log (x <> y) 8 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ReExportQualified/A.purs: -------------------------------------------------------------------------------- 1 | module A where 2 | 3 | x = "Do" 4 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ReExportQualified/B.purs: -------------------------------------------------------------------------------- 1 | module B where 2 | 3 | y = "ne" 4 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ReExportQualified/C.purs: -------------------------------------------------------------------------------- 1 | module C (module A, module M2) where 2 | 3 | import A 4 | import B as M2 5 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/RebindableSyntax.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | example1 :: String 7 | example1 = do 8 | "Do" 9 | " notation" 10 | " for" 11 | " Semigroup" 12 | where 13 | discard x f = x <> f unit 14 | 15 | applySecond :: forall f a b. Apply f => f a -> f b -> f b 16 | applySecond fa fb = const identity <$> fa <*> fb 17 | 18 | infixl 4 applySecond as *> 19 | 20 | newtype Const a b = Const a 21 | 22 | runConst :: forall a b. Const a b -> a 23 | runConst (Const a) = a 24 | 25 | instance functorConst :: Functor (Const a) where 26 | map _ (Const a) = Const a 27 | 28 | instance applyConst :: Semigroup a => Apply (Const a) where 29 | apply (Const a1) (Const a2) = Const (a1 <> a2) 30 | 31 | example2 :: Const String Unit 32 | example2 = do 33 | Const "Do" 34 | Const " notation" 35 | Const " for" 36 | Const " Apply" 37 | where 38 | discard x f = x *> f unit 39 | 40 | main = do 41 | log example1 42 | log $ runConst example2 43 | log "Done" 44 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Recursion.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | fib = \n -> case n of 7 | 0.0 -> 1.0 8 | 1.0 -> 1.0 9 | n -> fib (n - 1.0) + fib (n - 2.0) 10 | 11 | main = log "Done" 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/RedefinedFixity.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import M3 4 | import Effect.Console (log) 5 | 6 | main = log "Done" 7 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/RedefinedFixity/M1.purs: -------------------------------------------------------------------------------- 1 | module M1 where 2 | 3 | applyFn :: forall a b. (forall c d. c -> d) -> a -> b 4 | applyFn f a = f a 5 | 6 | infixr 1000 applyFn as $ 7 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/RedefinedFixity/M2.purs: -------------------------------------------------------------------------------- 1 | module M2 where 2 | 3 | import M1 4 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/RedefinedFixity/M3.purs: -------------------------------------------------------------------------------- 1 | module M3 where 2 | 3 | import M1 4 | import M2 5 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ReservedWords.purs: -------------------------------------------------------------------------------- 1 | -- See https://github.com/purescript/purescript/issues/606 2 | module Main where 3 | 4 | import Prelude 5 | import Effect 6 | import Effect.Console (log) 7 | 8 | o :: { type :: String } 9 | o = { type: "o" } 10 | 11 | p :: { type :: String } 12 | p = o { type = "p" } 13 | 14 | f :: forall r. { type :: String | r } -> String 15 | f { type: "p" } = "Done" 16 | f _ = "Fail" 17 | 18 | main :: Effect _ 19 | main = log $ f { type: p.type, foo: "bar" } 20 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ResolvableScopeConflict.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import A (thing) 4 | import B 5 | import Effect.Console (log) 6 | 7 | -- Not an error as although we have `thing` in scope from both A and B, it is 8 | -- imported explicitly from A, giving it a resolvable solution. 9 | what :: Boolean -> Int 10 | what true = thing 11 | what false = zing 12 | 13 | main = log "Done" 14 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ResolvableScopeConflict/A.purs: -------------------------------------------------------------------------------- 1 | module A where 2 | 3 | thing :: Int 4 | thing = 1 5 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ResolvableScopeConflict/B.purs: -------------------------------------------------------------------------------- 1 | module B where 2 | 3 | thing :: Int 4 | thing = 2 5 | 6 | zing :: Int 7 | zing = 3 8 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ResolvableScopeConflict2.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import A 4 | import Effect.Console (log) 5 | 6 | thing :: Int 7 | thing = 1 8 | 9 | -- Not an error as although we have `thing` in scope from both Main and A, 10 | -- as the local declaration takes precedence over the implicit import 11 | what :: Boolean -> Int 12 | what true = thing 13 | what false = zing 14 | 15 | main = log "Done" 16 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ResolvableScopeConflict2/A.purs: -------------------------------------------------------------------------------- 1 | module A where 2 | 3 | thing :: Int 4 | thing = 2 5 | 6 | zing :: Int 7 | zing = 3 8 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ResolvableScopeConflict3.purs: -------------------------------------------------------------------------------- 1 | module Main (thing, main, module A) where 2 | 3 | import A 4 | import Effect.Console (log) 5 | 6 | thing :: Int 7 | thing = 2 8 | 9 | main = log "Done" 10 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ResolvableScopeConflict3/A.purs: -------------------------------------------------------------------------------- 1 | module A where 2 | 3 | thing :: Int 4 | thing = 1 5 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/RowConstructors.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | type Foo = (x :: Number | (y :: Number | (z :: Number))) 7 | type Bar = (x :: Number, y :: Number, z :: Number) 8 | type Baz = { w :: Number | Bar } 9 | 10 | foo :: { | Foo } 11 | foo = { x: 0.0, y: 0.0, z: 0.0 } 12 | 13 | bar :: { | Bar } 14 | bar = { x: 0.0, y: 0.0, z: 0.0 } 15 | 16 | id' :: Record Foo -> Record Bar 17 | id' = identity 18 | 19 | foo' :: { | Foo } 20 | foo' = id' foo 21 | 22 | bar' :: { | Bar } 23 | bar' = id' bar 24 | 25 | baz :: Baz 26 | baz = { x: 0.0, y: 0.0, z: 0.0, w: 0.0 } 27 | 28 | type Quux r = (q :: Number | r) 29 | type Norf r = (q' :: Number | Quux r) 30 | 31 | quux :: { f :: { | Foo } | Quux Bar } 32 | quux = { f: foo', x: 0.0, y: 0.0, z: 0.0, q: 0.0 } 33 | 34 | quux' :: { | Norf Bar } 35 | quux' = { x: 0.0, y: 0.0, z: 0.0, q: 0.0, q': 0.0 } 36 | 37 | wildcard :: { w :: Number | _ } -> Baz 38 | wildcard { w: w } = { x: w, y: w, z: w, w: w } 39 | 40 | wildcard' :: { | Quux _ } -> Number 41 | wildcard' { q: q } = q 42 | 43 | main = log "Done" 44 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/RowInInstanceHeadDetermined.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data Empty = Empty 7 | data Cons = Cons 8 | 9 | 10 | -- simple case 11 | class Simple a b | a -> b where c :: a -> b 12 | instance simple0 :: Simple Empty {} where c _ = {} 13 | instance simple1 :: Simple Cons {foo :: Cons} where c cons = {foo: cons} 14 | 15 | 16 | -- simple transitive example 17 | class Transitive a b c | a -> b, b -> c where d :: a -> c 18 | instance transitive :: Transitive Empty {} {} where d _ = {} 19 | 20 | 21 | -- transitive example with cycles 22 | class Cyclic a b c d | a -> b, b -> a 23 | , a -> c 24 | , c -> d, d -> c 25 | instance cyclic :: Cyclic Empty Empty {} {} 26 | 27 | 28 | -- Determined cycle 29 | class DeterminedCycle a b c | a -> b 30 | , b -> c, c -> b 31 | instance determinedCycle :: DeterminedCycle Empty {} {} 32 | 33 | 34 | -- multiple determiners 35 | class MultipleDeterminers a b c d | a b -> c d 36 | instance multipleDeterminers :: MultipleDeterminers Empty Empty {} {} 37 | 38 | 39 | main = log "Done" 40 | 41 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/RowLacks.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | import Prim.Row (class Lacks) 5 | import Type.Row (RProxy(..)) 6 | 7 | lacksX 8 | :: forall r 9 | . Lacks "x" r 10 | => RProxy r 11 | -> RProxy () 12 | lacksX _ = RProxy 13 | 14 | test1 :: RProxy () 15 | test1 = lacksX (RProxy :: RProxy (y :: Int, z :: String)) 16 | 17 | test2 :: forall r. Lacks "x" r => RProxy r -> RProxy () 18 | test2 _ = lacksX (RProxy :: RProxy (y :: Int, z :: String | r)) 19 | 20 | test3 :: RProxy () 21 | test3 = test2 (RProxy :: RProxy (a :: String)) 22 | 23 | main = log "Done" 24 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/RowNub.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | import Prim.Row (class Nub, class Union) 5 | import Type.Row (RProxy(..)) 6 | 7 | nubUnion 8 | :: forall r1 r2 r3 r4 9 | . Union r1 r2 r3 10 | => Nub r3 r4 11 | => RProxy r1 12 | -> RProxy r2 13 | -> RProxy r4 14 | nubUnion _ _ = RProxy 15 | 16 | type InL = (x :: Int, y :: String) 17 | type InR = (x :: String, y :: Int, z :: Boolean) 18 | type Out = (x :: Int, y :: String, z :: Boolean) 19 | 20 | test :: RProxy Out 21 | test = nubUnion (RProxy :: RProxy InL) (RProxy :: RProxy InR) 22 | 23 | main = log "Done" 24 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/RowPolyInstanceContext.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | class T s m | m -> s where 7 | state :: (s -> s) -> m Unit 8 | 9 | data S s a = S (s -> { new :: s, ret :: a }) 10 | 11 | instance st :: T s (S s) where 12 | state f = S $ \s -> { new: f s, ret: unit } 13 | 14 | test1 :: forall r . S { foo :: String | r } Unit 15 | test1 = state $ \o -> o { foo = o.foo <> "!" } 16 | 17 | test2 :: forall m r . T { foo :: String | r } m => m Unit 18 | test2 = state $ \o -> o { foo = o.foo <> "!" } 19 | 20 | main = do 21 | let t1 = test1 22 | let t2 = test2 23 | log "Done" 24 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/RowUnion.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | PURS_FFI_FUNC_3(Main_merge, _, _l, _r) { 4 | const purs_record_t *l = purs_any_force_record(_l); 5 | const purs_record_t *r = purs_any_force_record(_r); 6 | purs_any_t ret = purs_any_record(purs_record_merge(l, r)); 7 | PURS_RC_RELEASE(l); 8 | PURS_RC_RELEASE(r); 9 | return ret; 10 | } 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/RowUnion.h: -------------------------------------------------------------------------------- 1 | #ifndef Main_H 2 | #define Main_H 3 | 4 | #include 5 | 6 | PURS_FFI_EXPORT(Main_merge); 7 | 8 | #endif // Main_H 9 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/RowUnion.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | exports.merge = function (dict) { 4 | return function (l) { 5 | return function (r) { 6 | var o = {}; 7 | return Object.assign(o, r, l); 8 | }; 9 | }; 10 | }; 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/RowsInInstanceContext.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect (Effect) 5 | import Effect.Console (log) 6 | import Data.Newtype (class Newtype, unwrap) 7 | 8 | class TypeEquals a b | a -> b, b -> a where 9 | coerce :: a -> b 10 | coerceBack :: b -> a 11 | 12 | instance refl :: TypeEquals a a where 13 | coerce = identity 14 | coerceBack = identity 15 | 16 | newtype RecordNewtype = RecordNewtype { x :: String } 17 | 18 | instance newtypeRecordNewtype :: 19 | TypeEquals inner { x :: String } 20 | => Newtype RecordNewtype inner where 21 | wrap = RecordNewtype <<< coerce 22 | unwrap (RecordNewtype rec) = coerceBack rec 23 | 24 | main :: Effect Unit 25 | main = log (unwrap (RecordNewtype { x: "Done" })).x 26 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/RunFnInline.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | 5 | import Effect.Console (log) 6 | 7 | runFn3 :: forall a b c d. (a -> b -> c -> d) -> a -> b -> c -> d 8 | runFn3 f a b c = f a b c 9 | 10 | main = do 11 | log $ runFn3 (\a b c -> c) 1 2 "Done" 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/RuntimeScopeIssue.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log, logShow) 5 | 6 | class A a where 7 | a :: a -> Boolean 8 | 9 | class B a where 10 | b :: a -> Boolean 11 | 12 | instance aNumber :: A Number where 13 | a 0.0 = true 14 | a n = b (n - 1.0) 15 | 16 | instance bNumber :: B Number where 17 | b 0.0 = false 18 | b n = a (n - 1.0) 19 | 20 | main = do 21 | logShow $ a 10.0 22 | log "Done" 23 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ScopedTypeVariables.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | test1 :: forall a. (a -> a) -> a -> a 7 | test1 f x = g (g x) 8 | where 9 | g :: a -> a 10 | g y = f (f y) 11 | 12 | test2 :: forall a. (a -> a) -> a -> a 13 | test2 = h 14 | where 15 | h :: forall b. (b -> b) -> b -> b 16 | h f x = g (g x) 17 | where 18 | g :: b -> b 19 | g y = f (f y) 20 | 21 | test3 :: Number 22 | test3 = ((\b -> b :: b) :: forall b. b -> b) 0.0 23 | 24 | test4 :: forall a. (a -> a) -> a -> a 25 | test4 = h 26 | where 27 | h :: forall b. (b -> b) -> b -> b 28 | h f x = g (g x) 29 | where 30 | g :: b -> b 31 | g y = j (f (f y)) 32 | where 33 | j :: forall b. b -> b 34 | j x = x 35 | 36 | 37 | main = log "Done" 38 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Sequence.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Effect.Console (log) 6 | 7 | data List a = Cons a (List a) | Nil 8 | 9 | class Sequence t where 10 | sequence :: forall m a. Monad m => t (m a) -> m (t a) 11 | 12 | instance sequenceList :: Sequence List where 13 | sequence Nil = pure Nil 14 | sequence (Cons x xs) = Cons <$> x <*> sequence xs 15 | 16 | main = sequence $ Cons (log "Done") Nil 17 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/SequenceDesugared.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Effect.Console (log) 6 | 7 | data List a = Cons a (List a) | Nil 8 | 9 | data Sequence t = Sequence (forall m a. Monad m => t (m a) -> m (t a)) 10 | 11 | sequence :: forall t. Sequence t -> (forall m a. Monad m => t (m a) -> m (t a)) 12 | sequence (Sequence s) = s 13 | 14 | sequenceListSeq :: forall m a. Monad m => List (m a) -> m (List a) 15 | sequenceListSeq Nil = pure Nil 16 | sequenceListSeq (Cons x xs) = Cons <$> x <*> sequenceListSeq xs 17 | 18 | sequenceList :: Sequence List 19 | sequenceList = Sequence (sequenceListSeq) 20 | 21 | sequenceList' :: Sequence List 22 | sequenceList' = Sequence ((\val -> case val of 23 | Nil -> pure Nil 24 | Cons x xs -> Cons <$> x <*> sequence sequenceList' xs)) 25 | 26 | sequenceList'' :: Sequence List 27 | sequenceList'' = Sequence (sequenceListSeq :: forall m a. Monad m => List (m a) -> m (List a)) 28 | 29 | sequenceList''' :: Sequence List 30 | sequenceList''' = Sequence ((\val -> case val of 31 | Nil -> pure Nil 32 | Cons x xs -> Cons <$> x <*> sequence sequenceList''' xs) :: forall m a. Monad m => List (m a) -> m (List a)) 33 | 34 | main = do 35 | void $ sequence sequenceList $ Cons (log "Done") Nil 36 | void $ sequence sequenceList' $ Cons (log "Done") Nil 37 | void $ sequence sequenceList'' $ Cons (log "Done") Nil 38 | void $ sequence sequenceList''' $ Cons (log "Done") Nil 39 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ShadowedModuleName.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Test 4 | import Effect.Console 5 | 6 | data Test = Test 7 | 8 | main = log (runZ (Z "Done")) 9 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ShadowedModuleName/Test.purs: -------------------------------------------------------------------------------- 1 | module Test where 2 | 3 | data Z = Z String 4 | 5 | runZ :: Z -> String 6 | runZ (Z s) = s 7 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ShadowedName.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console 5 | import Effect.Console (log) 6 | 7 | done :: String 8 | done = let str = "Not yet done" in 9 | let str = "Done" in str 10 | 11 | main = log done 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ShadowedRename.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Effect.Console 6 | import Test.Assert 7 | 8 | foo foo = let foo_1 = \_ -> foo 9 | foo_2 = foo_1 unit + 1.0 10 | in foo_2 11 | 12 | main = do 13 | assert $ foo 1.0 == 2.0 14 | log "Done" 15 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ShadowedTCO.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude hiding (add) 4 | import Effect.Console (log) 5 | 6 | runNat f = f 0.0 (\n -> n + 1.0) 7 | 8 | zero' z _ = z 9 | 10 | succ f zero' succ = succ (f zero' succ) 11 | 12 | add f g zero' succ = g (f zero' succ) succ 13 | 14 | one' = succ zero' 15 | two = succ one' 16 | four = add two two 17 | fourNumber = runNat four 18 | 19 | main = do 20 | log $ show fourNumber 21 | log "Done" 22 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/ShadowedTCOLet.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Partial.Unsafe (unsafePartial) 5 | import Effect 6 | import Effect.Console (log) 7 | 8 | f x y z = 9 | let f 1.0 2.0 3.0 = 1.0 10 | in f x z y 11 | 12 | main :: Effect _ 13 | main = do 14 | log $ show $ unsafePartial f 1.0 3.0 2.0 15 | log "Done" 16 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/SignedNumericLiterals.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | p = 0.5 7 | q = 1.0 8 | x = -1.0 9 | y = -0.5 10 | z = 0.5 11 | w = 1.0 12 | 13 | f :: Number -> Number 14 | f x = -x 15 | 16 | test1 = 2.0 - 1.0 17 | 18 | main = log "Done" 19 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/SolvingAppendSymbol.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | import Prim.Symbol (class Append) 6 | import Type.Data.Symbol (SProxy(..), reflectSymbol) 7 | import Type.Data.Symbol (append) as Symbol 8 | 9 | sym :: SProxy "" 10 | sym = SProxy 11 | 12 | symA :: SProxy "A" 13 | symA = SProxy 14 | 15 | symB :: SProxy "B" 16 | symB = SProxy 17 | 18 | egAB :: SProxy "AB" 19 | egAB = Symbol.append symA symB 20 | 21 | egBA :: SProxy "BA" 22 | egBA = Symbol.append symB symA 23 | 24 | egA' :: SProxy "A" 25 | egA' = Symbol.append sym (Symbol.append symA sym) 26 | 27 | main = do 28 | let gotAB = reflectSymbol egAB == "AB" 29 | gotBA = reflectSymbol egBA == "BA" 30 | gotA' = reflectSymbol egA' == "A" 31 | when (not gotAB) $ log "Did not get AB" 32 | when (not gotBA) $ log "Did not get BA" 33 | when (not gotA') $ log "Did not get A" 34 | when (gotAB && gotBA && gotA') $ log "Done" 35 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/SolvingCompareSymbol.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | import Prim.Symbol (class Compare) 6 | import Prim.Ordering (kind Ordering, LT, EQ, GT) 7 | import Type.Data.Symbol (SProxy(..)) 8 | import Type.Data.Symbol (compare) as Symbol 9 | import Type.Data.Ordering (OProxy(..), reflectOrdering) 10 | 11 | symA :: SProxy "A" 12 | symA = SProxy 13 | 14 | symB :: SProxy "B" 15 | symB = SProxy 16 | 17 | egLT :: OProxy LT 18 | egLT = Symbol.compare symA symB 19 | 20 | egEQ :: OProxy EQ 21 | egEQ = Symbol.compare symA symA 22 | 23 | egGT :: OProxy GT 24 | egGT = Symbol.compare symB symA 25 | 26 | main = do 27 | let gotLT = reflectOrdering egLT == LT 28 | gotEQ = reflectOrdering egEQ == EQ 29 | gotGT = reflectOrdering egGT == GT 30 | when (not gotLT) $ log "Did not get LT" 31 | when (not gotEQ) $ log "Did not get EQ" 32 | when (not gotGT) $ log "Did not get GT" 33 | when (gotLT && gotEQ && gotGT) $ log "Done" 34 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/SolvingIsSymbol.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Effect.Console 6 | 7 | -- Here we import as alias of reflectSymbol without importing Data.Symbol. However, 8 | -- Data.Symbol should be implicitly imported as we have an instance of IsSymbol solved. 9 | import SolvingIsSymbol.Lib (literalSymbol, libReflectSymbol) 10 | 11 | main = do 12 | let lit = libReflectSymbol literalSymbol 13 | when (lit == "literal") (log "Done") 14 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/SolvingIsSymbol/Lib.purs: -------------------------------------------------------------------------------- 1 | module SolvingIsSymbol.Lib where 2 | 3 | import Data.Symbol 4 | 5 | literalSymbol :: SProxy "literal" 6 | literalSymbol = SProxy 7 | 8 | libReflectSymbol :: forall s. IsSymbol s => SProxy s -> String 9 | libReflectSymbol = reflectSymbol 10 | 11 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Stream.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | 5 | import Effect (Effect) 6 | import Effect.Console (log) 7 | 8 | class IsStream el s | s -> el where 9 | cons :: el -> (Unit -> s) -> s 10 | uncons :: s -> { head :: el, tail :: s } 11 | 12 | data Stream a = Stream a (Unit -> Stream a) 13 | 14 | instance streamIsStream :: IsStream a (Stream a) where 15 | cons x xs = Stream x xs 16 | uncons (Stream x f) = { head: x, tail: f unit } 17 | 18 | test :: forall el s. IsStream el s => s -> s 19 | test s = case uncons s of 20 | { head, tail } -> cons head \_ -> tail 21 | 22 | main :: Effect Unit 23 | main = do 24 | let dones :: Stream String 25 | dones = cons "Done" \_ -> dones 26 | log (uncons (test dones)).head 27 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/StringEdgeCases.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Records as Records 5 | import Symbols as Symbols 6 | 7 | main = do 8 | Records.main 9 | Symbols.main 10 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/StringEdgeCases/Records.purs: -------------------------------------------------------------------------------- 1 | module Records where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | import Test.Assert (assert') 6 | 7 | newtype AstralKeys = AstralKeys { "💡" :: Int, "💢" :: Int } 8 | newtype LoneSurrogateKeys = LoneSurrogateKeys { "\xdf06" :: Int, "\xd834" :: Int } 9 | 10 | testLoneSurrogateKeys = 11 | let 12 | expected = 5 13 | actual = (_."\xd801" <<< helper) { "\xd800": 5 } 14 | in 15 | assert' ("lone surrogate keys: " <> show actual) (expected == actual) 16 | 17 | where 18 | helper :: { "\xd800" :: Int } -> { "\xd801" :: Int } 19 | helper o = 20 | case o."\xd800" of 21 | x -> { "\xd801": x } 22 | 23 | testAstralKeys = 24 | let 25 | expected = 5 26 | actual = (_."💢" <<< helper) { "💡": 5 } 27 | in 28 | assert' ("astral keys: " <> show actual) (expected == actual) 29 | 30 | where 31 | helper :: { "💡" :: Int } -> { "💢" :: Int } 32 | helper o = 33 | case o."💡" of 34 | x -> { "💢": x } 35 | 36 | main = do 37 | testLoneSurrogateKeys 38 | testAstralKeys 39 | log "Done" 40 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/StringEdgeCases/Symbols.purs: -------------------------------------------------------------------------------- 1 | -- This is similar to StringEscapes except we are performing the same tests 2 | -- with Symbols (at the type level). 3 | 4 | module Symbols where 5 | 6 | import Prelude 7 | import Effect.Console (log) 8 | import Prim.Symbol (class Append) 9 | import Type.Data.Symbol (SProxy(..), reflectSymbol) 10 | import Type.Data.Symbol (append) as Symbol 11 | import Test.Assert (assert') 12 | 13 | highS :: SProxy "\xd834" 14 | highS = SProxy 15 | 16 | lowS :: SProxy "\xdf06" 17 | lowS = SProxy 18 | 19 | loneSurrogates :: Boolean 20 | loneSurrogates = reflectSymbol (Symbol.append highS lowS) == "\x1d306" 21 | 22 | outOfOrderSurrogates :: Boolean 23 | outOfOrderSurrogates = reflectSymbol (Symbol.append lowS highS) == "\xdf06\xd834" 24 | 25 | notReplacing :: Boolean 26 | notReplacing = reflectSymbol lowS /= "\xfffd" 27 | 28 | main = do 29 | assert' "lone surrogates may be combined into a surrogate pair" loneSurrogates 30 | assert' "lone surrogates may be combined out of order to remain lone surrogates" outOfOrderSurrogates 31 | assert' "lone surrogates are not replaced with the Unicode replacement character U+FFFD" notReplacing 32 | log "Done" 33 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/StringEscapes.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude ((==), (/=), (<>), discard) 4 | import Test.Assert (assert, assert') 5 | import Effect.Console (log) 6 | 7 | singleCharacter = "\0\b\t\n\v\f\r\"\\" == "\x0\x8\x9\xA\xB\xC\xD\x22\x5C" 8 | hex = "\x1D306\x2603\x3C6\xE0\x0" == "𝌆☃φà\0" 9 | decimal = "\119558\9731\966\224\0" == "𝌆☃φà\0" 10 | surrogatePair = "\xD834\xDF06" == "\x1D306" 11 | highSurrogate = "\xD834" 12 | lowSurrogate = "\xDF06" 13 | loneSurrogates = (highSurrogate <> lowSurrogate) == "\x1D306" 14 | outOfOrderSurrogates = (lowSurrogate <> highSurrogate) == "\xDF06\xD834" 15 | replacement = "\xFFFD" 16 | notReplacing = replacement /= highSurrogate 17 | 18 | main = do 19 | assert' "single-character escape sequences" singleCharacter 20 | assert' "hex escape sequences" hex 21 | assert' "decimal escape sequences" decimal 22 | assert' "astral code points are represented as a UTF-16 surrogate pair" surrogatePair 23 | assert' "lone surrogates may be combined into a surrogate pair" loneSurrogates 24 | assert' "lone surrogates may be combined out of order to remain lone surrogates" outOfOrderSurrogates 25 | assert' "lone surrogates are not replaced with the Unicode replacement character U+FFFD" notReplacing 26 | log "Done" 27 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Superclasses1.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log, logShow) 5 | 6 | class Su a where 7 | su :: a -> a 8 | 9 | class (Su a) <= Cl a where 10 | cl :: a -> a -> a 11 | 12 | instance suNumber :: Su Number where 13 | su n = n + 1.0 14 | 15 | instance clNumber :: Cl Number where 16 | cl n m = n + m 17 | 18 | test :: forall a. Cl a => a -> a 19 | test a = su (cl a a) 20 | 21 | main = do 22 | logShow $ test 10.0 23 | log "Done" 24 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Superclasses3.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console 5 | import Effect 6 | 7 | class Monad m <= MonadWriter w m where 8 | tell :: w -> m Unit 9 | 10 | testFunctor :: forall m. Monad m => m Number -> m Number 11 | testFunctor n = (+) 1.0 <$> n 12 | 13 | test :: forall w m. Monad m => MonadWriter w m => w -> m Unit 14 | test w = do 15 | tell w 16 | tell w 17 | tell w 18 | 19 | data MTrace a = MTrace (Effect a) 20 | 21 | runMTrace :: forall a. MTrace a -> Effect a 22 | runMTrace (MTrace a) = a 23 | 24 | instance functorMTrace :: Functor MTrace where 25 | map = liftM1 26 | 27 | instance applyMTrace :: Apply MTrace where 28 | apply = ap 29 | 30 | instance applicativeMTrace :: Applicative MTrace where 31 | pure = MTrace <<< pure 32 | 33 | instance bindMTrace :: Bind MTrace where 34 | bind m f = MTrace (runMTrace m >>= (runMTrace <<< f)) 35 | 36 | instance monadMTrace :: Monad MTrace 37 | 38 | instance writerMTrace :: MonadWriter String MTrace where 39 | tell s = MTrace (log s) 40 | 41 | main = runMTrace $ test "Done" 42 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TCO.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log, logShow) 5 | import Control.Monad.Rec.Class 6 | import Data.Array ((..), span, length) 7 | 8 | main = do 9 | let f x = x + 1 10 | let v = 0 11 | logShow (applyN 0 f v) 12 | logShow (applyN 1 f v) 13 | logShow (applyN 2 f v) 14 | logShow (applyN 3 f v) 15 | logShow (applyN 4 f v) 16 | 17 | let largeArray = 1..10000 18 | logShow (length (span (\_ -> true) largeArray).init) 19 | 20 | logShow (tailRec (\n -> if n < 10000 then Loop (n + 1) else Done 42) 0) 21 | 22 | log "Done" 23 | 24 | applyN :: forall a. Int -> (a -> a) -> a -> a 25 | applyN = go identity 26 | where 27 | go f n _ | n <= 0 = f 28 | go f n g = go (f >>> g) (n - 1) g 29 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TCOCase.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data Data = One | More Data 7 | 8 | main = log (from (to 10000.0 One)) 9 | where 10 | to 0.0 a = a 11 | to n a = to (n - 1.0) (More a) 12 | from One = "Done" 13 | from (More d) = from d 14 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TailCall.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log, logShow) 5 | 6 | data L a = C a (L a) | N 7 | 8 | test :: Number -> L Number -> Number 9 | test n N = n 10 | test n (C x xs) = test (n + x) xs 11 | 12 | loop :: forall a. Number -> a 13 | loop x = loop (x + 1.0) 14 | 15 | notATailCall = \x -> 16 | (\notATailCall -> notATailCall x) (\x -> x) 17 | 18 | main = do 19 | logShow (test 0.0 (1.0 `C` (2.0 `C` (3.0 `C` N)))) 20 | log "Done" 21 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Tick.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | test' x = x 7 | 8 | main = log "Done" 9 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TopLevelCase.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | gcd :: Number -> Number -> Number 7 | gcd 0.0 x = x 8 | gcd x 0.0 = x 9 | gcd x y | x > y = gcd (x `mod` y) y 10 | gcd x y = gcd (y `mod` x) x 11 | 12 | guardsTest [x] | x > 0.0 = [] 13 | guardsTest xs = xs 14 | 15 | data A = A 16 | 17 | parseTest A 0.0 = 0.0 18 | 19 | main = log "Done" 20 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TransitiveImport.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Middle 5 | import Effect.Console 6 | 7 | main = do 8 | logShow (middle unit) 9 | log "Done" 10 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TransitiveImport/Middle.purs: -------------------------------------------------------------------------------- 1 | module Middle where 2 | 3 | import Test (test) 4 | 5 | middle = test 6 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TransitiveImport/Test.purs: -------------------------------------------------------------------------------- 1 | module Test where 2 | 3 | import Prelude 4 | 5 | class TestCls a where 6 | test :: a -> a 7 | 8 | instance unitTestCls :: TestCls Unit where 9 | test _ = unit 10 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TypeClassMemberOrderChange.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | class Test a where 7 | fn :: a -> a -> a 8 | val :: a 9 | 10 | instance testBoolean :: Test Boolean where 11 | val = true 12 | fn x y = y 13 | 14 | main = do 15 | log (show (fn true val)) 16 | log "Done" 17 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TypeClasses.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | test1 = \_ -> show "testing" 7 | 8 | f :: forall a. Show a => a -> String 9 | f x = show x 10 | 11 | test2 = \_ -> f "testing" 12 | 13 | test7 :: forall a. Show a => a -> String 14 | test7 = show 15 | 16 | test8 = \_ -> show $ "testing" 17 | 18 | data Data a = Data a 19 | 20 | instance showData :: Show a => Show (Data a) where 21 | show (Data a) = "Data (" <> show a <> ")" 22 | 23 | test3 = \_ -> show (Data "testing") 24 | 25 | instance functorData :: Functor Data where 26 | map = liftM1 27 | 28 | instance applyData :: Apply Data where 29 | apply = ap 30 | 31 | instance applicativeData :: Applicative Data where 32 | pure = Data 33 | 34 | instance bindData :: Bind Data where 35 | bind (Data a) f = f a 36 | 37 | instance monadData :: Monad Data 38 | 39 | data Maybe a = Nothing | Just a 40 | 41 | instance functorMaybe :: Functor Maybe where 42 | map = liftM1 43 | 44 | instance applyMaybe :: Apply Maybe where 45 | apply = ap 46 | 47 | instance applicativeMaybe :: Applicative Maybe where 48 | pure = Just 49 | 50 | instance bindMaybe :: Bind Maybe where 51 | bind Nothing _ = Nothing 52 | bind (Just a) f = f a 53 | 54 | instance monadMaybe :: Monad Maybe 55 | 56 | test4 :: forall a m. Monad m => a -> m Number 57 | test4 = \_ -> pure 1.0 58 | 59 | test5 = \_ -> Just 1.0 >>= \n -> pure (n + 1.0) 60 | 61 | ask r = r 62 | 63 | runReader r f = f r 64 | 65 | test9 _ = runReader 0.0 $ do 66 | n <- ask 67 | pure $ n + 1.0 68 | 69 | main = do 70 | log (test7 "Hello") 71 | log "Done" 72 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TypeClassesInOrder.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | class Foo a where 7 | foo :: a -> String 8 | 9 | instance fooString :: Foo String where 10 | foo s = s 11 | 12 | main = log $ foo "Done" 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TypeClassesWithOverlappingTypeVariables.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data Either a b = Left a | Right b 7 | 8 | instance functorEither :: Functor (Either a) where 9 | map _ (Left x) = Left x 10 | map f (Right y) = Right (f y) 11 | 12 | main = log "Done" 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TypeDecl.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | k :: String -> Number -> String 7 | k x y = x 8 | 9 | iterate :: forall a. Number -> (a -> a) -> a -> a 10 | iterate 0.0 f a = a 11 | iterate n f a = iterate (n - 1.0) f (f a) 12 | 13 | main = log "Done" 14 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TypeOperators.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import A (type (~>), type (/\), (/\)) 4 | import Effect.Console (log) 5 | 6 | natty ∷ ∀ f. f ~> f 7 | natty x = x 8 | 9 | data Compose f g a = Compose (f (g a)) 10 | 11 | testPrecedence1 ∷ ∀ f g. Compose f g ~> Compose f g 12 | testPrecedence1 x = x 13 | 14 | testPrecedence2 ∷ ∀ f g. f ~> g → f ~> g 15 | testPrecedence2 nat fx = nat fx 16 | 17 | swap ∷ ∀ a b. a /\ b → b /\ a 18 | swap (a /\ b) = b /\ a 19 | 20 | main = log "Done" 21 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TypeOperators/A.purs: -------------------------------------------------------------------------------- 1 | module A 2 | ( Tuple(..) 3 | , type (/\) 4 | , (/\) 5 | , Natural 6 | , type (~>) 7 | ) where 8 | 9 | data Tuple a b = Tuple a b 10 | 11 | infixl 6 Tuple as /\ 12 | infixl 6 type Tuple as /\ 13 | 14 | type Natural f g = ∀ a. f a → g a 15 | 16 | infixr 0 type Natural as ~> 17 | 18 | tup ∷ ∀ a b. a → b → b /\ a 19 | tup a b = b /\ a 20 | 21 | tupX ∷ ∀ a b c. a /\ b /\ c → c 22 | tupX (a /\ b /\ c) = c 23 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TypeSynonymInData.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | type A a = Array a 7 | 8 | data Foo a = Foo (A a) | Bar 9 | 10 | foo (Foo []) = Bar 11 | 12 | main = log "Done" 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TypeSynonyms.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | type Lens a b = 7 | { get :: a -> b 8 | , set :: a -> b -> a 9 | } 10 | 11 | composeLenses :: forall a b c. Lens a b -> Lens b c -> Lens a c 12 | composeLenses = \l1 -> \l2 -> 13 | { get: \a -> l2.get (l1.get a) 14 | , set: \a c -> l1.set a (l2.set (l1.get a) c) 15 | } 16 | 17 | type Pair a b = { fst :: a, snd :: b } 18 | 19 | fst :: forall a b. Lens (Pair a b) a 20 | fst = 21 | { get: \p -> p.fst 22 | , set: \p a -> { fst: a, snd: p.snd } 23 | } 24 | 25 | test1 :: forall a b c. Lens (Pair (Pair a b) c) a 26 | test1 = composeLenses fst fst 27 | 28 | main = log "Done" 29 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TypeWildcards.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | testTopLevel :: _ -> _ 7 | testTopLevel n = n + 1.0 8 | 9 | test :: forall a. Eq a => (a -> a) -> a -> a 10 | test f a = go (f a) a 11 | where 12 | go :: _ -> _ -> _ 13 | go a1 a2 | a1 == a2 = a1 14 | go a1 _ = go (f a1) a1 15 | 16 | main = log "Done" 17 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TypeWildcardsRecordExtension.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | foo :: forall a. {b :: Number | a} -> {b :: Number | _} 7 | foo f = f 8 | 9 | main = log "Done" 10 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TypeWithoutParens.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Lib (X, Y) 4 | import Effect.Console (log) 5 | 6 | idX :: X -> X 7 | idX x = x 8 | 9 | idY :: Y -> Y 10 | idY y = y 11 | 12 | main = log "Done" 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TypeWithoutParens/Lib.purs: -------------------------------------------------------------------------------- 1 | module Lib (X, Y) where 2 | 3 | data X = X 4 | type Y = X 5 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TypedBinders.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data Tuple a b = Tuple a b 7 | 8 | class MonadState s m where 9 | get :: m s 10 | put :: s -> m Unit 11 | 12 | data State s a = State (s -> Tuple s a) 13 | 14 | runState s (State f) = f s 15 | 16 | instance functorState :: Functor (State s) where 17 | map = liftM1 18 | 19 | instance applyState :: Apply (State s) where 20 | apply = ap 21 | 22 | instance applicativeState :: Applicative (State s) where 23 | pure a = State $ \s -> Tuple s a 24 | 25 | instance bindState :: Bind (State s) where 26 | bind f g = State $ \s -> case runState s f of 27 | Tuple s1 a -> runState s1 (g a) 28 | 29 | instance monadState :: Monad (State s) 30 | 31 | instance monadStateState :: MonadState s (State s) where 32 | get = State (\s -> Tuple s s) 33 | put s = State (\_ -> Tuple s unit) 34 | 35 | modify :: forall m s. Monad m => MonadState s m => (s -> s) -> m Unit 36 | modify f = do 37 | s <- get 38 | put (f s) 39 | 40 | test :: Tuple String String 41 | test = runState "" $ do 42 | modify $ (<>) "World!" 43 | modify $ (<>) "Hello, " 44 | str :: String <- get 45 | pure str 46 | 47 | test2 :: (Int -> Int) -> Int 48 | test2 = (\(f :: Int -> Int) -> f 10) 49 | 50 | test3 :: Int -> Boolean 51 | test3 n = case n of 52 | (0 :: Int) -> true 53 | _ -> false 54 | 55 | test4 :: Tuple Int Int -> Tuple Int Int 56 | test4 = (\(Tuple a b :: Tuple Int Int) -> Tuple b a) 57 | 58 | type Int1 = Int 59 | 60 | test5 :: Int1 -> Int1 61 | test5 = \(x :: Int1) -> x 62 | 63 | main = do 64 | let t1 = test 65 | t2 = test2 identity 66 | t3 = test3 1 67 | t4 = test4 (Tuple 1 0) 68 | log "Done" 69 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/TypedWhere.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data E a b = L a | R b 7 | 8 | data L a = C a (L a) | N 9 | 10 | lefts :: forall a b. L (E a b) -> L a 11 | lefts = go N 12 | where 13 | go :: forall a b. L a -> L (E a b) -> L a 14 | go ls N = ls 15 | go ls (C (L a) rest) = go (C a ls) rest 16 | go ls (C _ rest) = go ls rest 17 | 18 | main = log "Done" 19 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/UTF8Sourcefile.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console 4 | 5 | -- '→' is multibyte sequence \u2192. 6 | utf8multibyte = "Hello λ→ world!!" 7 | 8 | main = log "Done" 9 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/UnderscoreIdent.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | data Data_type = Con_Structor | Con_2 String 7 | 8 | type Type_name = Data_type 9 | 10 | done (Con_2 s) = s 11 | done _ = "Failed" 12 | 13 | main = log (done (Con_2 "Done")) 14 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/UnicodeIdentifier.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | f asgård = asgård 6 | 7 | main = log (f "Done") 8 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/UnicodeOperators.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | compose :: forall a b c. (b -> c) -> (a -> b) -> a -> c 6 | compose f g a = f (g a) 7 | 8 | infixr 9 compose as ∘ 9 | 10 | test1 = (\x -> x) ∘ \y -> y 11 | 12 | elem :: forall a b. a -> (a -> Boolean) -> Boolean 13 | elem x f = f x 14 | 15 | infixl 1 elem as ∈ 16 | 17 | emptySet :: forall a. a -> Boolean 18 | emptySet _ = true 19 | 20 | test2 = 1 ∈ emptySet 21 | 22 | main = log "Done" 23 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/UnicodeType.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | class Monad m ⇐ Monad1 m where 7 | f1 :: m Int 8 | 9 | class Monad m <= Monad2 m where 10 | f2 :: m Int 11 | 12 | f ∷ ∀ m. Monad m ⇒ Int → m Int 13 | f n = do 14 | n' ← pure n 15 | pure n' 16 | 17 | f' :: forall m. Monad m => Int -> m Int 18 | f' n = do 19 | n' <- pure n 20 | pure n' 21 | 22 | main = log "Done" 23 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/UnifyInTypeInstanceLookup.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | data Z = Z 6 | data S n = S n 7 | 8 | data T 9 | data F 10 | 11 | class EQ x y b 12 | instance eqT :: EQ x x T 13 | instance eqF :: EQ x y F 14 | 15 | test :: forall a b. EQ a b T => a -> b -> a 16 | test a _ = a 17 | 18 | spin :: forall a b. a -> b 19 | spin a = spin a 20 | 21 | -- Expected type: 22 | -- forall t. (EQ t (S Z) T) => t 23 | test1 = test (spin 1) (S Z) 24 | 25 | main = log "Done" 26 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Unit.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (logShow, log) 5 | 6 | main = do 7 | logShow (const unit $ "Hello world") 8 | log "Done" 9 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/UnknownInTypeClassLookup.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | class EQ a b 7 | 8 | instance eqAA :: EQ a a 9 | 10 | test :: forall a b. EQ a b => a -> b -> String 11 | test _ _ = "Done" 12 | 13 | runTest a = test a a 14 | 15 | main = log $ runTest 0.0 16 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/UnsafeCoerce.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude (Unit) 4 | import Unsafe.Coerce (unsafeCoerce) 5 | import Effect (Effect) 6 | import Effect.Console (log) 7 | 8 | x :: Number 9 | x = unsafeCoerce 1 10 | 11 | y :: Number 12 | y = case unsafeCoerce 1 of 13 | z -> unsafeCoerce z 14 | 15 | main :: Effect Unit 16 | main = log "Done" 17 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/UntupledConstraints.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | class Show a <= Nonsense a where 7 | method :: a -> a 8 | 9 | data Box a = Box a 10 | 11 | instance showBox :: Show a => Show (Box a) where 12 | show (Box a) = "Box " <> show a 13 | 14 | strangeThing :: forall m. Semigroup (m Unit) => m Unit -> m Unit -> m Unit 15 | strangeThing x y = x <> y 16 | 17 | main = log "Done" 18 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/UsableTypeClassMethods.purs: -------------------------------------------------------------------------------- 1 | -- this is testing that we don't see an `UnusableDeclaration` error for type 2 | -- class methods that should be valid based on various configurations of fundeps 3 | module Main where 4 | 5 | import Effect.Console (log) 6 | 7 | -- no fundeps 8 | class C0 a b where 9 | c0 :: a -> b 10 | 11 | -- simple fundep 12 | class C1 a b | a -> b where 13 | c1 :: a 14 | c1' :: a -> b 15 | 16 | -- transitive 17 | class C2 a b c | a -> b, b -> c where 18 | c2 :: a 19 | c2' :: a -> b 20 | c2'' :: a -> c 21 | c2''' :: a -> b -> c 22 | 23 | -- with cycles 24 | class C3 a b c | a -> b, b -> a, b -> c where 25 | c3 :: a 26 | c3' :: b 27 | c3'' :: a -> c 28 | c3''' :: b -> c 29 | c3'''' :: a -> b -> c 30 | 31 | -- nullary class 32 | class C4 where 33 | c4 :: forall a. a 34 | 35 | main = log "Done" 36 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/Where.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Partial.Unsafe (unsafePartial) 5 | import Effect 6 | import Effect.Console (logShow, log) 7 | 8 | test1 x = y 9 | where 10 | y :: Number 11 | y = x + 1.0 12 | 13 | test2 x y = x' + y' 14 | where 15 | x' = x + 1.0 16 | y' = y + 1.0 17 | 18 | test3 = f 1.0 2.0 3.0 19 | where f x y z = x + y + z 20 | 21 | test4 = f (+) [1.0, 2.0] 22 | where f x [y, z] = x y z 23 | 24 | test5 = g 10.0 25 | where 26 | f x | x > 0.0 = g (x / 2.0) + 1.0 27 | f x = 0.0 28 | g x = f (x - 1.0) + 1.0 29 | 30 | test6 = if f true then f 1.0 else f 2.0 31 | where f :: forall a. a -> a 32 | f x = x 33 | 34 | test7 :: Number -> Number 35 | test7 x = go x 36 | where 37 | go y | (x - 0.1 < y * y) && (y * y < x + 0.1) = y 38 | go y = go $ (y + x / y) / 2.0 39 | 40 | main :: Effect _ 41 | main = do 42 | logShow (test1 1.0) 43 | logShow (test2 1.0 2.0) 44 | logShow test3 45 | unsafePartial (logShow test4) 46 | logShow test5 47 | logShow test6 48 | logShow (test7 100.0) 49 | log "Done" 50 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/WildcardInInstance.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect 5 | import Effect.Console 6 | 7 | class Monad m <= MonadAsk r m | m -> r where 8 | ask :: m r 9 | 10 | instance monadAskFun :: MonadAsk r ((->) r) where 11 | ask = identity 12 | 13 | -- This should generate a warning with the correct inferred type. 14 | test :: forall m. MonadAsk _ m => m Int 15 | test = do 16 | x <- ask 17 | pure (x + 1) 18 | 19 | main :: Effect Unit 20 | main = do 21 | log "Done" 22 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/WildcardType.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | f1 :: (_ -> _) -> _ 7 | f1 g = g 1 8 | 9 | f2 :: _ -> _ 10 | f2 _ = "Done" 11 | 12 | main = log $ f1 f2 13 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/iota.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Effect.Console (log) 4 | 5 | s = \x -> \y -> \z -> x z (y z) 6 | 7 | k = \x -> \y -> x 8 | 9 | iota = \x -> x s k 10 | 11 | main = log "Done" 12 | -------------------------------------------------------------------------------- /upstream/tests/purs/passing/s.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | import Effect.Console (log) 5 | 6 | s = \x y z -> x z (y z) 7 | 8 | main = log "Done" 9 | -------------------------------------------------------------------------------- /upstream/tests/support/.gitignore: -------------------------------------------------------------------------------- 1 | /bower_components/ 2 | /node_modules/ 3 | /.pulp-cache/ 4 | /output/ 5 | /generated-docs/ 6 | /.psc-package/ 7 | /.psc* 8 | /.purs* 9 | /.psa* 10 | /.spago 11 | -------------------------------------------------------------------------------- /upstream/tests/support/spago.dhall: -------------------------------------------------------------------------------- 1 | { name = 2 | "support" 3 | , dependencies = 4 | [ "arrays" 5 | , "assert" 6 | , "bifunctors" 7 | , "console" 8 | , "control" 9 | , "distributive" 10 | , "effect" 11 | , "either" 12 | , "foldable-traversable" 13 | , "functions" 14 | , "gen" 15 | , "generics-rep" 16 | , "identity" 17 | , "integers" 18 | , "invariant" 19 | , "lazy" 20 | , "lists" 21 | , "math" 22 | , "maybe" 23 | , "newtype" 24 | , "nonempty" 25 | , "partial" 26 | , "prelude" 27 | , "proxy" 28 | , "refs" 29 | , "st" 30 | , "tailrec" 31 | , "tuples" 32 | , "type-equality" 33 | , "typelevel-prelude" 34 | , "unfoldable" 35 | , "unsafe-coerce" 36 | ] 37 | , packages = 38 | ./packages.dhall 39 | , sources = 40 | [ "src/**/*.purs", "test/**/*.purs" ] 41 | } 42 | --------------------------------------------------------------------------------