I have one function first with type: Int -> [a] -> (Error ([a],[a])) and a second function second with type: [a] -> [a] -> [a]
I am trying to make a third function now that uses the above functions.
the type I have for this function is: [Int] -> [a] -> Error [a]
I have been given these types to work around so cant change them.
This is what I tried:
last :: [Int] -> [a] -> Error [a]
last (x:xs) list = second (first x list)
Can you pass outputs from functions that use the error function in to others?
Assuming
Erroris an error monad, you can use the monadic bind operator (>>=) and theuncurryfunction:uncurrytransforms Q from a function with two arguments (aka a curried function) into a function on pairs. This means thatuncurry Q :: ([a], [a]) -> [a]The bind operator takes a value out of a monad and passes it into a monadic function. Here we’re extracting the value of the Error monad returned by
Fand passing it toQ, now turned into a monadic function that works on a pair of lists, thanks toreturnanduncurry.