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

Unresolved implicit parameter #468

Open
TimWhiting opened this issue Feb 9, 2024 Discussed in #467 · 4 comments
Open

Unresolved implicit parameter #468

TimWhiting opened this issue Feb 9, 2024 Discussed in #467 · 4 comments

Comments

@TimWhiting
Copy link
Collaborator

Discussed in #467

Originally posted by woojamon February 8, 2024
May I ask why the show function is not implicity resolved in the example below?

// main.kk

type myType
  MyCase(value:int)

fun show(result:error<myType>) : pure string
  match result
    Ok(m) -> "MyCase"
    Error(x) -> exn/show(x)

fun eq(left:error<myType>, right:error<myType>) : pure bool
  match (left,right)
    (Ok(_),Ok(_)) -> True
    (Error(l), Error(r)) -> l.message == r.message
    _ -> False

pub fun myFun(p1:a, p2:a, ?eq:(a,a) -> pure bool, ?show:a -> pure string) 
  "hello"

fun main()
  myFun(Ok(MyCase(1)),Ok(MyCase(2)))

main.kk(19,36): error: cannot resolve implicit parameter
context : myFun(Ok(MyCase(1)),Ok(MyCase(2)))
parameter : ?show : (error) -> pure string
candidates: ...
hint : add a (implicit) parameter to the function signature?

This seems like a bug

@TimWhiting
Copy link
Collaborator Author

TimWhiting commented Feb 9, 2024

@woojamon

Explicitly adding ,?show=show works, but the above example without the explicit show should ideally work as well.

Ahh, I think I figured it out. The main function isn't in the same recursive definition group as show because it doesn't use show explicitly. This means that it could be type checked prior to show is defined. You can move the datatype / helper function to its own file, or even do something as simple as calling show("") and it type checks fine.

@woojamon
Copy link

woojamon commented Feb 9, 2024

Ok, I'll move some things to their own files. Thanks!

@woojamon
Copy link

woojamon commented Feb 9, 2024

Wait, why doesn't eq suffer the same problem then?

@TimWhiting
Copy link
Collaborator Author

It just happens to be typed checked prior to main, or is uniquely named.

daanx added a commit that referenced this issue Mar 28, 2024
…to source locations (without violating dependencies), issue #468
TimWhiting pushed a commit to TimWhiting/koka that referenced this issue Apr 12, 2024
…to source locations (without violating dependencies), issue koka-lang#468
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants