Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type error doesn't match #25

Open
damdamo opened this issue Jul 25, 2019 · 0 comments
Open

Type error doesn't match #25

damdamo opened this issue Jul 25, 2019 · 0 comments
Labels
bug Something isn't working

Comments

@damdamo
Copy link
Collaborator

damdamo commented Jul 25, 2019

I've written a little example about a bank user and its account.

// Example: addMoney(#user(name: "coco", age: 10, account: #account(10, 100)), 50)

type User :: #nil or #user(name: String, age: Int, account: Account)
type Account :: #empty or #account(_ interest: Int, _ money: Int)

func addMoney(_ user: User, _ moneyAdd: Int) -> User ::
  match(user)
  with #nil ::
    #nil
  with #user(name: let nom , age: let age, account: let account) ::
    match(account)
    // with #empty ::
    //  #nil 
    with #account(let interest, let money) ::
      #user(name: nom, age: age, account: #account(interest, money + moneyAdd))

The code above works if I comment:

with #empty ::
  #nil 

Otherwise, I have this error:

l.29:c.5: type error: type '#empty' doesn't match '#account(_: $8, _: $9)':
    match(account) 

In Account, I've defined two cases, but the #empty case isn't recognize.
I've tested a case with only Account but everything works:

// foo(account: #account(10,10))

func foo(account: Account) -> User ::
  match(account)
  with #empty ::
    #nil
  with #account(let interest, let money) ::
    #nil
@damdamo damdamo added the bug Something isn't working label Jul 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant