Open joshi-monster opened 3 days ago
Probably not related to the error message, but using a curried function fixes the problem:
fn f(input: Int) -> String {
use result: String <- input |> function.curry2(use_test)
"The result is: " <> result
}
compiles and works as expected.
Hello! As the error says that function takes 2 arguments, but only one is being supplied.
Use does not have a special case for the pipe operator, it always behaves consistently with anything on the right hand side.
Hey, sorry for following up, but I'm not quite sure I understand how I should interpret that error. I would have expected a normal arity mismatch
error, or for the expected/found types to be the other way around, since the compiler expected a single-argument function either way (whichever it de-sugars first), but I provided one that takes 2 arguments instead.
Don't get me wrong, I think it's totally reasonable for this sort of thing to not be supported. Having to search for the last bit in a long pipeline after use <-
can lead to code that is hard to read. I just think the error message is not very helpful :)
I would interpret the error I got as a bug in the error reporting or even the type checker:
use_test
function. So the type of this function does not fitfn(Int, fn(String) -> a) -> a
, but this is exactly the type that use_test
has, why does the compiler think it's something else?fn(Int) -> a
that doesn't exist in my code. Even partially applying the use
callback would yield fn(Int) -> String
, so I don't quite understand how the compiler came up with this type.expected fn(fn(String) -> String) -> String, found a value of type a
)joshi~
Ah! Ok! Thank you for that info. I understand better now and was too hasty before.
I'll read through this again and think about what to do later, it's lunch time :)
Hi! π
I noticed this after adding a
|> result.try
at the end of a long pipeline anduse
- ing the result. I've made a simplified example demonstrating the problem:produces the following type error:
Playing with the types for a bit, it seems like the "Expected type" here is always just the type of the function at the end of the pipeline, and the "Found type" is the type of the function with the second argument (the
callback
) partially applied.When the function expects more than 2 arguments, you get an "Incorrect arity" error instead, even when providing the remaining "middle" arguments to the function (
Expected N arguments, got N-2
)