ich Haskell bin mit in der Schule und eine der Übungen, die ich tun muß, ist eine Funktion zu machen, die mir die Wurzeln einer quadratischen Gleichung ergibt, wenn ich ihm seine Koeffizienten geben, eine vorherige Funktion, die sagt mir, wie viele Lösungen es hat. Hier ist, was ich getan habe:Haskell Quadratic solution finder - Fehler
Erste Funktion, dieser funktioniert:
nRoots :: Float -> Float -> Float -> Int
nRoots a b c | r<0 = 0
| r==0 = 1
| otherwise = 2
where r = b^2-4*a*c
Zweite Funktion, funktioniert es nicht:
roots :: Float -> Float -> Float -> [Float]
roots a b c | nRoots==2 = [(-b-sqrt(b^2-4*a*c))/(2*a),(-b+sqrt(b^2-4*a*c))/(2*a)]
| nRoots==1 = [-b/(2*a)]
| otherwise = []
Hier ist der Fehler, den ich bekommen:
raizes.hs:8:21:
No instance for (Eq (Float -> Float -> Float -> Int))
(maybe you haven't applied enough arguments to a function?)
arising from a use of ‘==’
In the expression: nRoots == 2
In a stmt of a pattern guard for
an equation for ‘roots’:
nRoots == 2
In an equation for ‘roots’:
roots a b c
| nRoots == 2
= [(- b - sqrt (b^2 - 4 * a * c))/(2 * a),
(- b + sqrt (b^2 - 4 * a * c))/(2 * a)]
| nRoots == 1 = [- b/(2 * a)]
| otherwise = []
raizes.hs:8:23:
No instance for (Num (Float -> Float -> Float -> Int))
(maybe you haven't applied enough arguments to a function?)
arising from the literal ‘2’
In the second argument of ‘(==)’, namely ‘2’
In the expression: nRoots == 2
In a stmt of a pattern guard for
an equation for ‘roots’:
nRoots == 2
Irgendeine Idee, was vor sich geht ??
Vielen Dank im Voraus
EDIT: Vielen Dank für die Antworten! Ich fühle mich ziemlich dumm jetzt nicht es zu merken: X