Sto imparando Haskell. Ho creato una funzione che restituisce la tabella di moltiplicazione fino a 'n' nella base 'b'. I numeri sono riempiti con cifre 'w'. Come ultimo passo, voglio calcolare 'w' automaticamente. Perché questo non è compilato?Nessuna istanza per (Floating Int)
-- Number of digits needed for the multiplication table n*n in base 'base'
nOfDg :: Int -> Int-> Int
nOfDg n base = 1 + floor (logBase base (n*n))
errore:
No instance for (Floating Int)
arising from a use of `logBase' at C:\haskel\dgnum.hs:4:24-38
Possible fix: add an instance declaration for (Floating Int)
In the first argument of `floor', namely `(logBase b (n * n))'
In the second argument of `(+)', namely `floor (logBase b (n * n))'
In the expression: 1 + floor (logBase b (n * n))
Suppongo che avrete bisogno anche di '(fromIntegral base)'. –
@Jason: non con il tipo Dan ha dato quella funzione, non lo farai. – Chuck
Sì, dipende da come lo vuoi usare. O farlo come se fosse OK cambiare la firma del tipo, o usare la versione di Andy se no. –