[Haskell-cafe] Type inference problem with division (/)

noa noandrews at gmail.com
Tue Oct 30 20:31:25 EDT 2007


I have the following function:

theRemainder :: [String] -> [String] -> Double
theRemainder xs xt = sum( map additional (unique xs) )
	additional x = poccur * (inf [ppos,pneg]) --inf takes [Double]
		xsxt = zip xs xt
		pi = countPos xr -- countPos returns an Int
		ni = (length xr) - pi
		len = length xs
		len2 = length xr
		ppos = pi/len2 -- THESE ARE THE PROBLEM
		pneg = ni/len2 -- THESE ARE THE PROBLEM
		poccur = (pi+ni)/len
		xr = (filter ((\y -> (fst y)==x)) (xsxt))

And I am getting this error message with ghc:

    Couldn't match expected type `Double' against inferred type `Int'
    In the expression: ppos
    In the first argument of `inf', namely `[ppos, pneg]'
    In the second argument of `(*)', namely `(inf [ppos, pneg])'

How can I change the declaration of ppos nad pneg so they are treated as
Double for the inf function?

View this message in context: http://www.nabble.com/Type-inference-problem-with-division-%28-%29-tf4722111.html#a13500475
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

More information about the Haskell-Cafe mailing list