Error passing parameters through haskell function -
i'm receiving error , don't know why.
mapo :: ((float, float) -> float) -> [(float, float)] -> [float] mapo f [] = [] mapo f (x:y) = f x : mapo f y compiles ok.
*main> mapo + [(1,2)] couldn't match type `(float, float) -> (float, float)' `float' expected type: (float, float) -> float actual type: (float, float) -> (float, float) -> (float, float) in first argument of `mapo', namely `(+)' in expression: mapo (+) [(1, 2)] in equation `it': = mapo (+) [(1, 2)] the purpose of function receive operator (let's + or -), list of pairs of numbers (float) , return result of using operator each of pairs of parameters of list.
your problem merely syntactic error; when want partially apply operator need wrap in parentheses; instead of
mapo + [(1,2)] write
mapo (+) [(1,2)] otherwise parses adding mapo [(1,2)] (i.e. (+) mapo [(1,2)] not want.
next thing getting type right:
(+) :: float -> float -> float (in case, real type more general) - function wants (float,float) -> float. these 2 types aren't equal, express pretty same thing can map between them curry :: ((a,b) -> c) -> -> b -> c , uncurry :: (a -> b -> c) -> (a,b) -> c functions. in case need pass uncurry (+) mapo function.
Comments
Post a Comment