Comment: | First implementation of the standard library. |
---|---|
Timelines: | family | ancestors | trunk |
Files: | files | file ages | folders |
SHA3-256: |
7e9c8cf531f01f680ccea8b0a5c06d3f |
User & Date: | robin.hansen on 2021-04-17 11:05:34 |
Other Links: | manifest | tags |
2021-04-17
| ||
11:05 | First implementation of the standard library. Leaf check-in: 7e9c8cf531 user: robin.hansen tags: trunk | |
11:04 | Add a couple of more functions to list module. Closed-Leaf check-in: 442b0f85ca user: robin.hansen tags: stdlib | |
2021-04-07
| ||
13:39 | Add cli program to compile projects, run functions and initiate new projects. check-in: 9318fc4c3b user: robin.hansen tags: trunk | |
Modified src/Play/Data/Type.elm from [7b6e93ee1b] to [7660e71094].
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
Custom name ->
name
CustomGeneric name _ ->
name
Union _ ->
"Union"
Quotation quotType ->
"[ " ++ wordTypeToString quotType ++ " ]"
StackRange name ->
name ++ "..."
|
| > > > > > > | > > |
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
Custom name -> name CustomGeneric name _ -> name Union members -> let memberString = members |> List.map toDisplayString |> String.join ", " in "Union(" ++ memberString ++ ")" Quotation quotType -> "[ " ++ wordTypeToString quotType ++ " ]" StackRange name -> name ++ "..." |
Modified src/Play/Qualifier.elm from [d1f74ef9ef] to [9fd8ef35a0].
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
...
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
|
Err err -> ( err :: errors , acc ) Ok qualifiedMembers -> ( errors , Dict.insert qualifiedName (CustomTypeDef qualifiedName range generics members) acc ) Parser.UnionTypeDef range name generics memberTypes -> let qualifiedName = qualifyName config name ................................................................................ else "quote:" ++ qualifyName config currentDefName ++ "/" ++ String.fromInt acc.availableQuoteId ( newWordsAfterQuot, externalWords, qualifiedQuotImplResult ) = initQualifyNode quoteName config acc.qualifiedWords quotImpl in case qualifiedQuotImplResult of Ok [ Word _ wordRef ] -> case Dict.get wordRef newWordsAfterQuot of Nothing -> Debug.todo "Cannot happen" Just oldWord -> { acc | qualifiedWords = Dict.insert wordRef { oldWord | metadata = Metadata.isQuoted oldWord.metadata } newWordsAfterQuot , qualifiedNodes = Ok (WordRef sourceLocation wordRef) :: acc.qualifiedNodes , externalWords = Set.union externalWords acc.externalWords } Ok qualifiedQuotImpl -> { acc | availableQuoteId = acc.availableQuoteId + 1 , qualifiedWords = Dict.insert quoteName { name = quoteName , metadata = |
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
...
618
619
620
621
622
623
624
625
626
627
628
629
630
631
|
Err err -> ( err :: errors , acc ) Ok qualifiedMembers -> ( errors , Dict.insert qualifiedName (CustomTypeDef qualifiedName range generics qualifiedMembers) acc ) Parser.UnionTypeDef range name generics memberTypes -> let qualifiedName = qualifyName config name ................................................................................ else "quote:" ++ qualifyName config currentDefName ++ "/" ++ String.fromInt acc.availableQuoteId ( newWordsAfterQuot, externalWords, qualifiedQuotImplResult ) = initQualifyNode quoteName config acc.qualifiedWords quotImpl in case qualifiedQuotImplResult of Ok qualifiedQuotImpl -> { acc | availableQuoteId = acc.availableQuoteId + 1 , qualifiedWords = Dict.insert quoteName { name = quoteName , metadata = |
Modified src/Play/TypeChecker.elm from [2a58b70563] to [03b15c559b].
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 ... 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 ... 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 ... 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 .... 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 |
Context -> Qualifier.WordDefinition -> List ( Qualifier.TypeMatch, List Qualifier.Node ) -> List Qualifier.Node -> Context typeCheckMultiImplementation context untypedDef initialWhens defaultImpl = let untypedDefMetadata = untypedDef.metadata untypedDefNoTypeAnnotation = { untypedDef | metadata = { untypedDefMetadata | type_ = TypeSignature.NotProvided } } whens = case defaultImpl of [] -> initialWhens _ -> let ( inferredDefaultType, _ ) = typeCheckImplementation untypedDefNoTypeAnnotation defaultImpl (cleanContext context) in case inferredDefaultType.input of [] -> Debug.todo "Default impl doesn't have an input argument" firstType :: _ -> ( Qualifier.TypeMatch SourceLocation.emptyRange firstType [], defaultImpl ) :: initialWhens ( inferredWhenTypes, newContext ) = List.foldr (inferWhenTypes untypedDefNoTypeAnnotation) ( [], context ) whens |> Tuple.mapFirst normalizeWhenTypes |> (\( wts, ctx ) -> simplifyWhenWordTypes wts ctx) |> Tuple.mapFirst (List.map2 Tuple.pair whenPatterns >> List.map replaceFirstTypeWithPatternMatch) |> Tuple.mapFirst equalizeWhenTypes |> Tuple.mapFirst (\whenTypes -> List.map (constrainGenerics untypedDef.metadata.type_) whenTypes) replaceFirstTypeWithPatternMatch ( Qualifier.TypeMatch _ matchType _, typeSignature ) = ................................................................................ inferWhenTypes : Qualifier.WordDefinition -> ( Qualifier.TypeMatch, List Qualifier.Node ) -> ( List WordType, Context ) -> ( List WordType, Context ) inferWhenTypes untypedDef ( _, im ) ( infs, ctx ) = let ( inf, newCtx ) = typeCheckImplementation untypedDef im (cleanContext ctx) in ( inf :: infs, newCtx ) normalizeWhenTypes : List WordType -> List WordType normalizeWhenTypes whenTypes = let ................................................................................ unzip ( left, right ) ( leftAcc, rightAcc ) = ( left :: leftAcc, right :: rightAcc ) constrainedInputs = List.map2 constrainAndZip firstType.input secondType.input constrainedOutputs = List.map2 constrainAndZip firstType.output secondType.output ( unzippedFirstInputs, unzippedSecondInputs ) = List.foldr unzip ( [], [] ) constrainedInputs ( unzippedFirstOutputs, unzippedSecondOutputs ) = List.foldr unzip ( [], [] ) constrainedOutputs newFirstType = { input = unzippedFirstInputs , output = unzippedFirstOutputs } newSecondType = { input = unzippedSecondInputs , output = unzippedSecondOutputs } in equalizeWhenTypesHelper remaining remappedGenerics (newSecondType :: newFirstType :: acc) ................................................................................ unionOfTypeMatches : List ( Qualifier.TypeMatch, a ) -> Type unionOfTypeMatches whenBranches = let uniqueTypes = whenBranches |> List.map (Tuple.first >> extractTypeFromTypeMatch) |> List.gatherEquals |> List.map Tuple.first in case uniqueTypes of [ singleType ] -> singleType _ -> Type.Union uniqueTypes ................................................................................ Type.Generic (genName ++ String.fromInt idx) Type.CustomGeneric name generics -> Type.CustomGeneric name (List.map (tagGeneric idx) generics) Type.Union members -> Type.Union (List.map (tagGeneric idx) members) _ -> type_ wordTypeToStackEffects : WordType -> List StackEffect wordTypeToStackEffects wordType = |
< < < < < < < < < < < | < < < > | | > > > > > > > > > > > > > > > > > > > > | < < < < < < | | > > > > > > > > > > > > > > > |
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 ... 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 ... 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 ... 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 .... 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 |
Context -> Qualifier.WordDefinition -> List ( Qualifier.TypeMatch, List Qualifier.Node ) -> List Qualifier.Node -> Context typeCheckMultiImplementation context untypedDef initialWhens defaultImpl = let whens = case defaultImpl of [] -> initialWhens _ -> let ( inferredDefaultType, _ ) = typeCheckImplementation untypedDef defaultImpl (cleanContext context) in case inferredDefaultType.input of [] -> Debug.todo "Default impl doesn't have an input argument" firstType :: _ -> ( Qualifier.TypeMatch SourceLocation.emptyRange firstType [], defaultImpl ) :: initialWhens ( inferredWhenTypes, newContext ) = whens |> List.foldr (inferWhenTypes untypedDef) ( [], context ) |> Tuple.mapFirst normalizeWhenTypes |> (\( wts, ctx ) -> simplifyWhenWordTypes wts ctx) |> Tuple.mapFirst (List.map2 Tuple.pair whenPatterns >> List.map replaceFirstTypeWithPatternMatch) |> Tuple.mapFirst equalizeWhenTypes |> Tuple.mapFirst (\whenTypes -> List.map (constrainGenerics untypedDef.metadata.type_) whenTypes) replaceFirstTypeWithPatternMatch ( Qualifier.TypeMatch _ matchType _, typeSignature ) = ................................................................................ inferWhenTypes : Qualifier.WordDefinition -> ( Qualifier.TypeMatch, List Qualifier.Node ) -> ( List WordType, Context ) -> ( List WordType, Context ) inferWhenTypes untypedDef ( Qualifier.TypeMatch _ t _, im ) ( infs, ctx ) = let alteredTypeSignature = case untypedDef.metadata.type_ of TypeSignature.UserProvided wt -> TypeSignature.UserProvided <| case wt.input of _ :: rest -> { wt | input = t :: rest } _ -> wt x -> x metadata = untypedDef.metadata alteredDef = { untypedDef | metadata = { metadata | type_ = alteredTypeSignature } } ( inf, newCtx ) = typeCheckImplementation alteredDef im (cleanContext ctx) in ( inf :: infs, newCtx ) normalizeWhenTypes : List WordType -> List WordType normalizeWhenTypes whenTypes = let ................................................................................ unzip ( left, right ) ( leftAcc, rightAcc ) = ( left :: leftAcc, right :: rightAcc ) constrainedInputs = List.map2 constrainAndZip firstType.input secondType.input ( unzippedFirstInputs, unzippedSecondInputs ) = List.foldr unzip ( [], [] ) constrainedInputs newFirstType = { input = unzippedFirstInputs , output = firstType.output } newSecondType = { input = unzippedSecondInputs , output = secondType.output } in equalizeWhenTypesHelper remaining remappedGenerics (newSecondType :: newFirstType :: acc) ................................................................................ unionOfTypeMatches : List ( Qualifier.TypeMatch, a ) -> Type unionOfTypeMatches whenBranches = let uniqueTypes = whenBranches |> List.map (Tuple.first >> extractTypeFromTypeMatch) |> List.concatMap flattenUnions |> List.gatherEquals |> List.map Tuple.first flattenUnions t = case t of Type.Union members -> List.concatMap flattenUnions members _ -> [ t ] in case uniqueTypes of [ singleType ] -> singleType _ -> Type.Union uniqueTypes ................................................................................ Type.Generic (genName ++ String.fromInt idx) Type.CustomGeneric name generics -> Type.CustomGeneric name (List.map (tagGeneric idx) generics) Type.Union members -> Type.Union (List.map (tagGeneric idx) members) Type.Quotation wt -> Type.Quotation { input = List.map (tagGeneric idx) wt.input , output = List.map (tagGeneric idx) wt.output } _ -> type_ wordTypeToStackEffects : WordType -> List StackEffect wordTypeToStackEffects wordType = |
Modified src/Play/TypeChecker/Problem.elm from [b183d4af4c] to [63d1018a02].
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
++ "' needs to be declared." TypeError range name actual expected -> SourceLocation.extractFromString source range ++ "\n\n" ++ "The type of '" ++ name ++ "' is specified to be: " ++ Type.wordTypeToString actual ++ ".\nHowever, it seems that the actual type is: " ++ Type.wordTypeToString expected UnexpectedType range name actual expected -> SourceLocation.extractFromString source range ++ "\n\n" ++ "Found a problem in the implementation of '" ++ name ++ "'.\n\nExpected: " ++ Type.toDisplayString expected ++ ".\nActual: " ++ Type.toDisplayString actual ++ "." InconsistentWhens range name -> SourceLocation.extractFromString source range ++ "\n\n" ++ "The branches of '" ++ name ++ "' do not all have the same type." |
| | | | < |
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
++ "' needs to be declared." TypeError range name actual expected -> SourceLocation.extractFromString source range ++ "\n\n" ++ "The type of '" ++ name ++ "' is specified to be:\n\n" ++ Type.wordTypeToString actual ++ "\n\nHowever, it seems that the actual type is:\n\n" ++ Type.wordTypeToString expected UnexpectedType range name actual expected -> SourceLocation.extractFromString source range ++ "\n\n" ++ "Found a problem in the implementation of '" ++ name ++ "'.\n\nExpected:\n\n" ++ Type.toDisplayString expected ++ "\n\nActual:\n" ++ Type.toDisplayString actual InconsistentWhens range name -> SourceLocation.extractFromString source range ++ "\n\n" ++ "The branches of '" ++ name ++ "' do not all have the same type." |
Deleted stdlib/lib/useless/junk version [a7ffc6f8bf].
Deleted stdlib/lib/version/play.json version [73b800a441].
1 2 3 4 5 6 7 8 9 10 11 12 |
{ "name": "play/version", "version": "1.0.0", "language-version": "0.2.0", "exposed-modules": [ "version/data" ], "dependencies": { }, "package-paths": [ ] } |
< < < < < < < < < < < < |
Deleted stdlib/lib/version/src/version/data.play version [f4d9804625].
1 2 |
def: minor : 1 |
< < |
Modified stdlib/play.json from [163a77ae7d] to [f2261f0ba9].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
{ "name": "play/standard_library", "version": "0.2.0", "language-version": "0.2.0", "exposed-modules": [ "basic" ], "dependencies": { "play/version": "1.0.0" }, "package-paths": [ "lib/*" ] } |
| > > > | < < | < < |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
{ "name": "play/standard_library", "version": "0.2.0", "language-version": "0.2.0", "exposed-modules": [ "core", "maybe", "pair", "list" ], "dependencies": {}, "package-paths": [] } |
Modified stdlib/src/core.play from [0ef79cb1cb] to [b4257695bb].
1 2 |
def: version : tmp/mod/major /version/data/minor + |
> > > > > > > > > > > > > > > > > > > > > > > > > | < > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# Everything in core is imported into every module outside the standard library # booleans defunion: Bool : True : False defstruct: True defstruct: False defmulti: not type: Bool -- Bool : True drop False : False drop True defmulti: select type: Bool a a -- a : True drop swap drop : False rotate drop2 def: if type: a... Bool [ a... -- b... ] [ a... -- b... ] -- b... : select ! # stack manipulation def: over type: a b -- a b a : swap dup rotate def: drop2 type: a b c -- a : drop drop def: split type: a [ a -- b ] [ a -- c ] -- b c : -rotate dup # [] [] a a -rotate ! # [] a c swap -rotate # c a [] ! # c b swap # numbers defmulti: zero? type: Int -- Bool : Int( value 0 ) drop True : Int drop False def: int= type: Int Int -- Bool : - zero? def: negate type: Int -- Int : dup dup - swap - def: square type: Int -- Int : dup * def: inc type: Int -- Int : 1 + def: dec type: Int -- Int : 1 - |
Added stdlib/src/list.play version [a7b678c1a9].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
defunion: List a : NonEmpty a : Empty defstruct: NonEmpty a : first a : rest (List a) defstruct: Empty def: of-one type: a -- (NonEmpty a) : Empty >NonEmpty def: of-two type: a a -- (NonEmpty a) : Empty >NonEmpty >NonEmpty def: of-three type: a a a -- (NonEmpty a) : Empty >NonEmpty >NonEmpty >NonEmpty defmulti: fold type: (List a) b [ a b -- b ] -- b : Empty drop swap drop : NonEmpty pair/>Pair swap # (Pair b quot) (NonEmpty a) [ first> ] [ rest> ] core/split # Pair first rest rotate swap # rest first Pair dup rotate # rest Pair first Pair pair/spill # rest Pair first b quot ! # rest Pair b swap pair/second> # rest b quot fold def: reverse type: (List a) -- (List a) : Empty [ >NonEmpty ] fold def: fold-right type: (List a) b [ a b -- b ] -- b : -rotate reverse rotate fold def: test : 1 2 3 of-three 0 [ + ] fold |
Added stdlib/src/maybe.play version [00d98b8fe3].
> > > > > > > > > > > > > > > > > > > > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
defunion: Maybe a : a : Nothing defstruct: Nothing defmulti: map type: (Maybe a) [ a -- b ] -- (Maybe b) : a ! : Nothing drop defmulti: when-nothing type: (Maybe a) a -- a : a drop : Nothing swap drop |
Added stdlib/src/pair.play version [0056df763e].
> > > > > > > > > > > > > > > > > > > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
defstruct: Pair a b : first a : second b def: spill type: (Pair a b) -- a b : [ first> ] [ second> ] core/split def: map type: (Pair a b) [ a b -- c d ] -- (Pair c d) : swap spill -rotate ! >Pair def: map-first type: (Pair a b) [ a -- c ] -- (Pair c b) : core/over first> swap ! >first def: map-second type: (Pair a b) [ b -- c ] -- (Pair a c) : core/over second> swap ! >second |
Deleted stdlib/src/tmp/mod.play version [2e69dc67e4].
1 2 |
def: major : 2 |
< < |
Modified tests/Test/Qualifier.elm from [34e6530c10] to [883b702e60].
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 ... 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 ... 849 850 851 852 853 854 855 856 857 858 859 860 861 862 |
, Builtin emptyRange Builtin.Minus ] } ] } in QualifierUtil.expectOutput unqualifiedAst expectedAst , test "Do not create new function if quoting exactly one word" <| \_ -> let unqualifiedAst = { types = Dict.empty , words = Dict.fromListBy .name [ { name = "main" , metadata = Metadata.default |> Metadata.asEntryPoint , implementation = AST.SoloImpl [ AST.Integer emptyRange 1 , AST.Quotation emptyRange ................................................................................ ] } expectedAst = { types = Dict.empty , words = Dict.fromListBy .name [ { name = "main" , metadata = Metadata.default |> Metadata.asEntryPoint , implementation = SoloImpl [ Integer emptyRange 1 , WordRef emptyRange "inc" , Builtin emptyRange Builtin.Apply ] } , { name = "inc" , metadata = Metadata.default |> Metadata.isQuoted , implementation = SoloImpl [ Integer emptyRange 1 , Builtin emptyRange Builtin.Plus ] } ] } in QualifierUtil.expectOutput unqualifiedAst expectedAst , test "Quotes within quotes is fine" <| ................................................................................ |> Metadata.withVerifiedType [ Type.Custom "/play/test/some/module/Cent" ] [ Type.Int ] , implementation = SoloImpl [ GetMember "/play/test/some/module/Cent" "cent-value" ] } ] } in QualifierUtil.expectModuleOutput unqualifiedAst expectedAst , describe "Module loading" [ test "Detects package reference in simple word" <| \_ -> let unqualifiedAst = |
| | | | > > > > > > > > | < > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 ... 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 ... 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 |
, Builtin emptyRange Builtin.Minus ] } ] } in QualifierUtil.expectOutput unqualifiedAst expectedAst , test "Quoting a word which hasn't been qualified yet is fine" <| \_ -> let unqualifiedAst = { types = Dict.empty , words = Dict.fromListBy .name [ { name = "a" , metadata = Metadata.default |> Metadata.asEntryPoint , implementation = AST.SoloImpl [ AST.Integer emptyRange 1 , AST.Quotation emptyRange ................................................................................ ] } expectedAst = { types = Dict.empty , words = Dict.fromListBy .name [ { name = "a" , metadata = Metadata.default |> Metadata.asEntryPoint , implementation = SoloImpl [ Integer emptyRange 1 , WordRef emptyRange "quote:a/1" , Builtin emptyRange Builtin.Apply ] } , { name = "inc" , metadata = Metadata.default , implementation = SoloImpl [ Integer emptyRange 1 , Builtin emptyRange Builtin.Plus ] } , { name = "quote:a/1" , metadata = Metadata.default |> Metadata.isQuoted , implementation = SoloImpl [ Word emptyRange "inc" ] } ] } in QualifierUtil.expectOutput unqualifiedAst expectedAst , test "Quotes within quotes is fine" <| ................................................................................ |> Metadata.withVerifiedType [ Type.Custom "/play/test/some/module/Cent" ] [ Type.Int ] , implementation = SoloImpl [ GetMember "/play/test/some/module/Cent" "cent-value" ] } ] } in QualifierUtil.expectModuleOutput unqualifiedAst expectedAst , test "member types are qualified" <| \_ -> let qualifiedUsMoneyUnion = [ Type.Custom "/play/test/some/module/Dollar" , Type.Custom "/play/test/some/module/Cent" ] unqualifiedAst = { types = Dict.fromListBy AST.typeDefinitionName [ AST.UnionTypeDef emptyRange "USMoney" [] [ Type.Custom "Dollar" , Type.Custom "Cent" ] , AST.CustomTypeDef emptyRange "Wallet" [] [ ( "user-id", Type.Int ) , ( "value", Type.Custom "USMoney" ) ] , AST.CustomTypeDef emptyRange "Dollar" [] [ ( "dollar-value", Type.Int ) ] , AST.CustomTypeDef emptyRange "Cent" [] [ ( "cent-value", Type.Int ) ] ] , words = Dict.empty } |> ParserUtil.addFunctionsForStructs expectedAst = { types = Dict.fromListBy typeDefinitionName [ UnionTypeDef "/play/test/some/module/USMoney" emptyRange [] qualifiedUsMoneyUnion , CustomTypeDef "/play/test/some/module/Dollar" emptyRange [] [ ( "dollar-value", Type.Int ) ] , CustomTypeDef "/play/test/some/module/Cent" emptyRange [] [ ( "cent-value", Type.Int ) ] , CustomTypeDef "/play/test/some/module/Wallet" emptyRange [] [ ( "user-id", Type.Int ) , ( "value", Type.Union qualifiedUsMoneyUnion ) ] ] , words = Dict.fromListBy .name [ { name = "/play/test/some/module/>Dollar" , metadata = Metadata.default |> Metadata.withVerifiedType [ Type.Int ] [ Type.Custom "/play/test/some/module/Dollar" ] , implementation = SoloImpl [ ConstructType "/play/test/some/module/Dollar" ] } , { name = "/play/test/some/module/>Cent" , metadata = Metadata.default |> Metadata.withVerifiedType [ Type.Int ] [ Type.Custom "/play/test/some/module/Cent" ] , implementation = SoloImpl [ ConstructType "/play/test/some/module/Cent" ] } , { name = "/play/test/some/module/>Wallet" , metadata = Metadata.default |> Metadata.withVerifiedType [ Type.Int, Type.Union qualifiedUsMoneyUnion ] [ Type.Custom "/play/test/some/module/Wallet" ] , implementation = SoloImpl [ ConstructType "/play/test/some/module/Wallet" ] } , { name = "/play/test/some/module/>dollar-value" , metadata = Metadata.default |> Metadata.withVerifiedType [ Type.Custom "/play/test/some/module/Dollar", Type.Int ] [ Type.Custom "/play/test/some/module/Dollar" ] , implementation = SoloImpl [ SetMember "/play/test/some/module/Dollar" "dollar-value" ] } , { name = "/play/test/some/module/>cent-value" , metadata = Metadata.default |> Metadata.withVerifiedType [ Type.Custom "/play/test/some/module/Cent", Type.Int ] [ Type.Custom "/play/test/some/module/Cent" ] , implementation = SoloImpl [ SetMember "/play/test/some/module/Cent" "cent-value" ] } , { name = "/play/test/some/module/>user-id" , metadata = Metadata.default |> Metadata.withVerifiedType [ Type.Custom "/play/test/some/module/Wallet", Type.Int ] [ Type.Custom "/play/test/some/module/Wallet" ] , implementation = SoloImpl [ SetMember "/play/test/some/module/Wallet" "user-id" ] } , { name = "/play/test/some/module/>value" , metadata = Metadata.default |> Metadata.withVerifiedType [ Type.Custom "/play/test/some/module/Wallet", Type.Union qualifiedUsMoneyUnion ] [ Type.Custom "/play/test/some/module/Wallet" ] , implementation = SoloImpl [ SetMember "/play/test/some/module/Wallet" "value" ] } , { name = "/play/test/some/module/dollar-value>" , metadata = Metadata.default |> Metadata.withVerifiedType [ Type.Custom "/play/test/some/module/Dollar" ] [ Type.Int ] , implementation = SoloImpl [ GetMember "/play/test/some/module/Dollar" "dollar-value" ] } , { name = "/play/test/some/module/cent-value>" , metadata = Metadata.default |> Metadata.withVerifiedType [ Type.Custom "/play/test/some/module/Cent" ] [ Type.Int ] , implementation = SoloImpl [ GetMember "/play/test/some/module/Cent" "cent-value" ] } , { name = "/play/test/some/module/user-id>" , metadata = Metadata.default |> Metadata.withVerifiedType [ Type.Custom "/play/test/some/module/Wallet" ] [ Type.Int ] , implementation = SoloImpl [ GetMember "/play/test/some/module/Wallet" "user-id" ] } , { name = "/play/test/some/module/value>" , metadata = Metadata.default |> Metadata.withVerifiedType [ Type.Custom "/play/test/some/module/Wallet" ] [ Type.Union qualifiedUsMoneyUnion ] , implementation = SoloImpl [ GetMember "/play/test/some/module/Wallet" "value" ] } ] } in QualifierUtil.expectModuleOutput unqualifiedAst expectedAst , describe "Module loading" [ test "Detects package reference in simple word" <| \_ -> let unqualifiedAst = |
Modified tests/Test/TypeChecker.elm from [7ab0558be9] to [51729be1c5].
397 398 399 400 401 402 403 404 405 406 407 408 409 410 ... 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 .... 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 |
Err err -> err |> List.map (Problem.toString "") |> String.join "\n" |> (++) "Did not expect type check to fail.\n" |> Expect.fail Ok _ -> Expect.pass , test "Generic custom type fails if not generic is listed" <| \_ -> let input = { types = ................................................................................ ] [ QAST.Builtin emptyRange Builtin.StackDrop , QAST.Integer emptyRange 1 ] } in case run input of Err _ -> Expect.fail "Did not expect type check to fail." Ok _ -> Expect.pass , test "With default branch (no type meta)" <| \_ -> let input = ................................................................................ in case run input of Ok _ -> Expect.pass Err _ -> Expect.fail "Did not expect type check to fail." , test "With generics" <| \_ -> let input = { types = Dict.empty , words = Dict.fromListBy .name |
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 ... 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 .... 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 |
Err err -> err |> List.map (Problem.toString "") |> String.join "\n" |> (++) "Did not expect type check to fail.\n" |> Expect.fail Ok _ -> Expect.pass , test "Generic types with generic quotations" <| \_ -> let listUnion = [ Type.Custom "Empty" , Type.CustomGeneric "NonEmpty" [ Type.Generic "a" ] ] input = { types = Dict.fromListBy QAST.typeDefinitionName [ QAST.CustomTypeDef "Pair" emptyRange [ "a", "b" ] [ ( "first", Type.Generic "a" ) , ( "second", Type.Generic "b" ) ] , QAST.UnionTypeDef "List" emptyRange [ "a" ] listUnion , QAST.CustomTypeDef "NonEmpty" emptyRange [ "a" ] [ ( "head", Type.Generic "a" ) , ( "rest", Type.Union listUnion ) ] , QAST.CustomTypeDef "Empty" emptyRange [] [] ] , words = Dict.fromListBy .name [ { name = "main" , metadata = Metadata.default |> Metadata.withType [] [ Type.Int ] , implementation = QAST.SoloImpl [ QAST.Integer emptyRange 1 , QAST.Integer emptyRange 2 , QAST.Integer emptyRange 3 , QAST.Word emptyRange "Empty" , QAST.Word emptyRange ">NonEmpty" , QAST.Word emptyRange ">NonEmpty" , QAST.Word emptyRange ">NonEmpty" , QAST.Integer emptyRange 0 , QAST.WordRef emptyRange "main__quot1" , QAST.Word emptyRange "fold" ] } , { name = "main__quot1" , metadata = Metadata.default , implementation = QAST.SoloImpl [ QAST.Builtin emptyRange Builtin.Plus ] } , { name = "fold" , metadata = Metadata.default |> Metadata.withType [ Type.Union listUnion , Type.Generic "b" , Type.Quotation { input = [ Type.Generic "a" , Type.Generic "b" ] , output = [ Type.Generic "b" ] } ] [ Type.Generic "b" ] , implementation = QAST.MultiImpl [ ( QAST.TypeMatch emptyRange (Type.Custom "Empty") [] , [ QAST.Builtin emptyRange Builtin.StackDrop , QAST.Builtin emptyRange Builtin.StackSwap , QAST.Builtin emptyRange Builtin.StackDrop ] ) , ( QAST.TypeMatch emptyRange (Type.CustomGeneric "NonEmpty" [ Type.Generic "a" ]) [] , [ QAST.Word emptyRange ">Pair" , QAST.Builtin emptyRange Builtin.StackSwap , QAST.WordRef emptyRange "fold_quot1" , QAST.WordRef emptyRange "fold_quot2" , QAST.Word emptyRange "split" , QAST.Builtin emptyRange Builtin.StackRightRotate , QAST.Builtin emptyRange Builtin.StackSwap , QAST.Builtin emptyRange Builtin.StackDuplicate , QAST.Builtin emptyRange Builtin.StackRightRotate , QAST.Word emptyRange "spill" , QAST.Builtin emptyRange Builtin.Apply , QAST.Builtin emptyRange Builtin.StackSwap , QAST.Word emptyRange "second>" , QAST.Word emptyRange "fold" ] ) ] [] } , { name = "fold_quot1" , metadata = Metadata.default |> Metadata.isQuoted , implementation = QAST.SoloImpl [ QAST.Word emptyRange "head>" ] } , { name = "fold_quot2" , metadata = Metadata.default |> Metadata.isQuoted , implementation = QAST.SoloImpl [ QAST.Word emptyRange "rest>" ] } , { name = "split" , metadata = Metadata.default |> Metadata.withType [ Type.Generic "a" , Type.Quotation { input = [ Type.Generic "a" ] , output = [ Type.Generic "b" ] } , Type.Quotation { input = [ Type.Generic "a" ] , output = [ Type.Generic "c" ] } ] [ Type.Generic "b" , Type.Generic "c" ] , implementation = QAST.SoloImpl [ QAST.Builtin emptyRange Builtin.StackLeftRotate , QAST.Builtin emptyRange Builtin.StackDuplicate , QAST.Builtin emptyRange Builtin.StackLeftRotate , QAST.Builtin emptyRange Builtin.Apply , QAST.Builtin emptyRange Builtin.StackSwap , QAST.Builtin emptyRange Builtin.StackLeftRotate , QAST.Builtin emptyRange Builtin.Apply , QAST.Builtin emptyRange Builtin.StackSwap ] } , { name = "spill" , metadata = Metadata.default |> Metadata.withType [ Type.CustomGeneric "Pair" [ Type.Generic "a" , Type.Generic "b" ] ] [ Type.Generic "a" , Type.Generic "b" ] , implementation = QAST.SoloImpl [ QAST.WordRef emptyRange "spill_quot1" , QAST.WordRef emptyRange "spill_quot2" , QAST.Word emptyRange "split" ] } , { name = "spill_quot1" , metadata = Metadata.default |> Metadata.isQuoted , implementation = QAST.SoloImpl [ QAST.Word emptyRange "first>" ] } , { name = "spill_quot2" , metadata = Metadata.default |> Metadata.isQuoted , implementation = QAST.SoloImpl [ QAST.Word emptyRange "second>" ] } ] } |> QualifierUtil.addFunctionsForStructs in case run input of Err err -> err |> Debug.log "err" |> List.map (Problem.toString "") |> String.join "\n" |> (++) "Did not expect type check to fail.\n" |> Expect.fail Ok _ -> Expect.pass , test "Generic custom type fails if not generic is listed" <| \_ -> let input = { types = ................................................................................ ] [ QAST.Builtin emptyRange Builtin.StackDrop , QAST.Integer emptyRange 1 ] } in case run input of Err err -> Expect.fail <| "Did not expect type check to fail." ++ Debug.toString err Ok _ -> Expect.pass , test "With default branch (no type meta)" <| \_ -> let input = ................................................................................ in case run input of Ok _ -> Expect.pass Err _ -> Expect.fail "Did not expect type check to fail." , test "Typechecking involving a multi-arity quotation is fine _if_ arity info is in type annotation" <| \_ -> let input = { types = Dict.empty , words = Dict.fromListBy .name [ { name = "apply-to-nums" , metadata = Metadata.default |> Metadata.withType [ Type.Quotation { input = [ Type.Int, Type.Int ] , output = [ Type.Int ] } ] [ Type.Int ] , implementation = QAST.SoloImpl [ QAST.Integer emptyRange 1 , QAST.Integer emptyRange 2 , QAST.Builtin emptyRange Builtin.StackLeftRotate , QAST.Builtin emptyRange Builtin.Apply ] } , { name = "main" , metadata = Metadata.default |> Metadata.asEntryPoint , implementation = QAST.SoloImpl [ QAST.WordRef emptyRange "main__quot1" , QAST.Word emptyRange "apply-to-nums" ] } , { name = "main__quot1" , metadata = Metadata.default |> Metadata.isQuoted , implementation = QAST.SoloImpl [ QAST.Builtin emptyRange Builtin.Plus ] } ] } in case run input of Ok _ -> Expect.pass Err err -> Expect.fail <| "Did not expect type check to fail:" ++ Debug.toString err , test "With generics" <| \_ -> let input = { types = Dict.empty , words = Dict.fromListBy .name |