Skip to content

Commit

Permalink
allow operator id's in fields (issue #557)
Browse files Browse the repository at this point in the history
  • Loading branch information
daanx committed Sep 20, 2024
1 parent 3527337 commit 8da3fea
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 6 deletions.
5 changes: 5 additions & 0 deletions lib/std/core/bool.kk
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ pub fip fun (>)( x : bool, y : bool) : bool
pub fip fun (>=)( x : bool, y : bool) : bool
!(x < y)

pub fip fun xor( x : bool, y : bool ) : bool
match x
False -> y
True -> !y

// Compare two booleans with `False < True`.
pub fip fun cmp( x : bool, y : bool) : order
if x < y then Lt
Expand Down
2 changes: 1 addition & 1 deletion lib/std/core/types.kk
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub infixr 20 (||)
// prefix (!), (-)


// build: 139
// build: 141

// ----------------------------------------------------------------------------
// Core types
Expand Down
4 changes: 2 additions & 2 deletions src/Syntax/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2544,13 +2544,13 @@ typeApp tp

paramType :: LexParser (Name,Range,UserType)
paramType
= do (id,rng) <- varid <|> wildcard <|> return (nameNil, rangeNull)
= do (id,rng) <- identifier <|> wildcard <|> return (nameNil, rangeNull)
keyword ":"
tp <- parameterType rng
return (id,rng,tp)

paramTypeX
= do (id,rng) <- try (do v <- varid <|> wildcard; keyword ":"; return v)
= do (id,rng) <- try (do v <- identifier <|> wildcard; keyword ":"; return v)
tp <- parameterType rng
return (id,rng,tp)
<|>
Expand Down
9 changes: 9 additions & 0 deletions test/cgen/field1.kk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
struct num<a>
(+) : ( x : a, y : a ) -> a
(*) : (a,a) -> a

val int/num : num<int>
= Num( (+), (*) )

pub fun main()
(num.(+))(1,2).println
1 change: 1 addition & 0 deletions test/cgen/field1.kk.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
File renamed without changes.
9 changes: 9 additions & 0 deletions test/cgen/pattern-match-in-param.kk.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
f(2, [1], Just([2, 3])) -> 6
f(1, [1], Just([1])) -> cgen/pattern-match-in-param(1,34): f: pattern match failure
g(1, 2) -> 1
h([2,3]) -> 2
h() -> 1
i(0) -> 1
j(0) -> 1
k([]) -> cgen/pattern-match-in-param(23,12): k: pattern match failure
l((1, 2, 3)) -> 1
File renamed without changes.
1 change: 1 addition & 0 deletions test/cgen/tail.kk.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0@25
File renamed without changes.
1 change: 1 addition & 0 deletions test/cgen/tail2.kk.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0@25
17 changes: 17 additions & 0 deletions test/overload/num1.kk
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
struct num<a>
plus : (a,a) -> a
zero : a

fun num/(+)( x : a, y : a, ?num : num<a> ) : a
(?num.plus)(x,y)

fun list/(+)( xs : list<a>, ys : list<a>, ?num : num<a> ) : a
zipwith(xs,ys,num/(+)).foldl(num.zero,num/(+))


val bool/num : num<bool> = Num( xor, False )
val int/num : num<int> = Num( int/(+), 0 )


pub fun main()
([1] + [2], True + False).println
10 changes: 10 additions & 0 deletions test/overload/num1.kk.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(3,True)

overload/num1/bool/num: num<bool>
overload/num1/int/num: num<int>
overload/num1/(+): forall<a> (xs : list<a>, ys : list<a>, ?num : num<a>) -> a
overload/num1/num/(+): forall<a> (x : a, y : a, ?num : num<a>) -> a
overload/num1/num/plus: forall<a> (num : num<a>) -> ((a, a) -> a)
overload/num1/num/zero: forall<a> (num : num<a>) -> a
overload/num1/Num: forall<a> (plus : (a, a) -> a, zero : a) -> num<a>
overload/num1/main: () -> console ()
3 changes: 0 additions & 3 deletions test/syntax/run/config.json

This file was deleted.

Empty file.
Empty file removed test/syntax/run/tail.kk.out
Empty file.
Empty file removed test/syntax/run/tail2.kk.out
Empty file.

0 comments on commit 8da3fea

Please sign in to comment.