ich konvertieren schrieb eine Funktion in HaskellWie von Float zu Int in Haskell
toInt :: Float -> Int
toInt x = round $fromIntegral x
Es soll in einem Float nehmen und die entsprechende Int zurückzukehren. Ich komme von einem C-Programmierhintergrund, und in C konnten wir es einfach als (int) x auffassen.
jedoch in diesem Fall erhalte ich den folgenden Compiler-Fehler
No instance for (Integral Float)
arising from a use of `fromIntegral'
In the second argument of `($)', namely `fromIntegral x'
In the expression: round $ fromIntegral x
In an equation for `toInt': toInt x = round $ fromIntegral x
Irgendeine Idee, wie man dieses Problem beheben?
Vielleicht können Sie dieses 'Runde 3.2 :: Int' versuchen. – Aleph0
Wenn Sie eine Funktion suchen müssen, von der Sie den Typ 'Float -> Int 'kennen, können Sie nach Funktionen dieses Typs suchen, entweder auf [Hayoo] (http://hayoo.fh-wedel.de/?query= Float + -% 3E + Int) oder [Hoogle] (https://www.haskell.org/hoogle/?hoogle=Float+-%3E+Int+%2bbase&start=41#more) – Redu