I'm working with Haskell, and trying to implement a higher-order function, but I'm having trouble understanding and testing the function because I'm unsure what an input would look like.
Since the function itself is part of a graded assignment, I can't ask for help regarding writing/implementing the function itself, so I've changed the function names and custom type names, so I can use the function as an example on what the input arguments would look like, if you were to type them into the console.
search :: ([(Int,Int)] -> [[(Int,Int)]]) -> ([(Int,Int)] -> Bool) -> [[(Int,Int)]] -> Maybe [(Int,Int)]
search function1 function2 listOfIntegerPairs
function1 takes a list of integer pairs as input and outputs a list of lists containing pairs of integers.
function2 takes a list of integer pairs and outputs a boolean.
I'm unsure as to how one might input the arguments for this higher-order function into the console.
i.e. Would it be something like this where we include the function and it's parameters as arguments?
search (function1([(0,0),(0,1)])) (function2([(0,0),(0,1)])) [(0,0),(0,1)]
This form produces errors, but I can't figure out what the input arguments would look like, and having trouble locating any articles/tutorials which illustrates it. Hence I can't test the function until I work out what the input function arguments look like types out.
Can anyone offer me some guidance? Is what I'm asking even possible?
a -> [a]
is not that of a function that "takes a list of integer pairs as inputs and outputs a list of lists containing pairs of integers", it's that of a function that takes a value and returns a list of values. This can be specialized to what you intend it to be, but you could also pass it e.g. aBool
. Also, the point of higher order functions is to pass another function as an argument, not the result of another function, that's regular order functions. Trysearch function1 function1 [(0,0),(0,1)]
. – bheklilrmyFunction1 :: bool -> [bool] myFunction1 b = [true, false, b]
or whatever you want yourmyFunction1
to be. Then you can passmyFunction1
as the argument. – lmmsearch
function is called in the same manner it's declared. Think of themap
function:map length ["this", "is", "a", "test"]
would return[4,2,1,4]
, it isn't called asmap (length ["this", "is", "a", "test"]) ["this", "is", "a", "test"]
, which wouldn't be the same anyway, since it would reduce to something likemap 4 ["this", "is", "a", "test"]
, since that argument list has length 4, and mapping the "function4
" is nonsensical. – bheklilrsearch
function has the same type signature. Haskell type signatures are very informative and useful, intentionally providing the wrong type signature when asking for help would be like asking for help finding a bug in a C++ function, but removing the lines that cause the bug in the question. – bheklilr