help with lists and tuples

Please can you help me with this? What I want is to have on input a list of tuple (size 2) and on output list of floats. So now I'm returning only float instead of a list. But unfortunately I can't figure out how to implement the list...... sigmoid :: Float -> Float sigmoid x = 1.0 / (1 + exp (-x)) nActivation :: (Float,Float) -> Float nActivation (x,y) = sigmoid(x*y) nActivationSum :: [(Float, Float)] -> [Float] nActivationSum [] = [] nActivationSum (inputs:weights) = *nActivation* (inputs, weights) Couldn't match expected type `[Float]' with actual type `Float' In the return type of a call of `nActivation' In the expression: nActivation (inputs, weights) In an equation for `nActivationSum': nActivationSum (inputs : weights) = nActivation (inputs, weights) thanks, m.

It seems like you want to set up a recursive function. So you want to take one tuple out of the list of tuples, perform your sum function on it, and then call the recursive function on the remainder of the list. Something like this, maybe?
nActivationSum :: [(Float, Float)] -> [Float]
nActivationSum [] = []
nActivationSum ((input,weight) : rest) = nActivation (input, weight) : nActivat\
ionSum rest
On 2013-04-14, at 4:04 PM, Miro Karpis
Please can you help me with this? What I want is to have on input a list of tuple (size 2) and on output list of floats. So now I'm returning only float instead of a list. But unfortunately I can't figure out how to implement the list......
sigmoid :: Float -> Float sigmoid x = 1.0 / (1 + exp (-x))
nActivation :: (Float,Float) -> Float nActivation (x,y) = sigmoid(x*y)
nActivationSum :: [(Float, Float)] -> [Float] nActivationSum [] = [] nActivationSum (inputs:weights) = nActivation (inputs, weights)
Couldn't match expected type `[Float]' with actual type `Float' In the return type of a call of `nActivation' In the expression: nActivation (inputs, weights) In an equation for `nActivationSum': nActivationSum (inputs : weights) = nActivation (inputs, weights)
thanks, m. _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

It looks like you want this instead:
nActivationSum :: [(Float, Float)] -> [Float]
nActivationSum (xy : xys) = nActivation xy : nActivationSum xys
nActivationSum [] = []
This pattern is more commonly expressed with map like this:
nActivationSum :: [(Float, Float)] -> [Float]
nActivationSum inputsAndWeights = map nActivation inputsAndWeights
Or you could write it a bit shorter in point-free style:
nActivationSum :: [(Float, Float)] -> [Float]
nActivationSum = map nActivation
On Sun, Apr 14, 2013 at 4:04 PM, Miro Karpis
Please can you help me with this? What I want is to have on input a list of tuple (size 2) and on output list of floats. So now I'm returning only float instead of a list. But unfortunately I can't figure out how to implement the list......
sigmoid :: Float -> Float sigmoid x = 1.0 / (1 + exp (-x))
nActivation :: (Float,Float) -> Float nActivation (x,y) = sigmoid(x*y)
nActivationSum :: [(Float, Float)] -> [Float] nActivationSum [] = [] nActivationSum (inputs:weights) = *nActivation* (inputs, weights)
Couldn't match expected type `[Float]' with actual type `Float' In the return type of a call of `nActivation' In the expression: nActivation (inputs, weights) In an equation for `nActivationSum': nActivationSum (inputs : weights) = nActivation (inputs, weights)
thanks, m.
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (3)
-
Alexander O'Neill
-
Bob Ippolito
-
Miro Karpis