I am trying to see if length of a given list equals some number. However ==
expects two numbers not Int, so even when I type (==) 1
type is still number -> Bool
so finally when I pipe in result of lenght
I get compilation error:
-- TYPE MISMATCH ---------------------------------------------------------- REPL
This function cannot handle the argument sent through the
(|>)
pipe:4| List.length |> ((==) 1) ^^^^^^
The argument is:
List a -> Int
But
(|>)
is piping it to a function that expects:number
Hint: Only Int and Float values work as numbers.
So how can I specify that my constant is an Int as opposed to number variable?
Use >>
to compose functions.
isLengthOne = List.length >> ((==) 1)
is a function that checks that the length of a list is 1.
|>
pipes the output of one statement to the input of the next.
So aList |> List.length |> ((==) 1)
would check aList
.