[Haskell-beginners] No accumulation of partially applied functions allowed?
Obscaenvs
obscaenvs at gmail.com
Tue Jun 26 22:08:49 CEST 2012
Sorry if this is a less than stellar question.
The problem:
Given a function f :: a -> a -> a -> b, make it work on a list instead:
f `applyTo`[x,y,z] where [x,y,z] :: [a].
My stab at a general solution was
`
applyTo f [] = error "no arg"
applyTo f (x:xs) = go (f x) xs
where
go acc [] = acc
go acc (y:[]) = acc y
go acc (y:ys) = go (acc $ y) ys
`
I thought this would work, functions being "first class citizens" but
ghci complains:
"Occurs check: cannot construct the infinite type: t1 = t0 -> t1
In the return type of a call of `acc'
Probable cause: `acc' is applied to too many arguments
In the expression: acc y
In an equation for `go': go acc (y : []) = acc y"
The 'probable cause' isn't the real cause here, but something to do with
the fact that it's impossible to accumulate functions in this way...
Or am I just too tired too make it work? I can see that the type of `go`
could be a problem, but is it insurmountable?
/F
More information about the Beginners
mailing list