qui ho una breve funzione di haskell che dovrebbe convertire "ABCDEF" in 0x41,0x42,0x43,0x44,0x45,0x46 (i loro valori ascii), quindi moltiplicarli in modo che diventi 0x4142,4344,4546 ma esso sembra limitare la lunghezza intera - pensavo che haskell usasse arbitrari bignum?La funzione Haskell sembra limitare la lunghezza intera - pensavo che usasse i bignum?
L'ultima riga del codice funziona bene, che mi
Tutte le idee puzzle? Grazie mille
import Data.Char
import Numeric
strToHex2 (h:[]) = ord h
strToHex2 (h:t) = (ord h) + ((strToHex2 t) * 256)
strToHex s = strToHex2 (reverse s)
main = do
print(strToHex "ABCDEF")
print ((((((((0x41*256+0x42)*256)+0x43)*256)+0x44)*256)+0x45)*256+0x46)
L'output è:
1128547654 <- limited to 32 bits for some reason?
71752852194630 <- that's fine
Vedere anche http://stackoverflow.com/questions/3429291/haskell-int-and-integer –
I tipi sono tuoi amici. Aggiungi le firme del tipo, ed è chiaro cosa sta succedendo! –