[Haskell-beginners] Code works in a file but not the interpreter

Oge kilop84 at gmail.com
Sat May 1 00:39:47 EDT 2010

Hi all,

This is my first post to haskell-beginners. I am trying to use the
SegmentTree-0.2 library from Hackage but I get an error when I try to
use some of its functions. For instance when I load a file containing
the following

module Stabbing.SegmentTree (counts) where
import Data.SegmentTree

counts :: [(Rational, Rational)] -> [Rational] -> [Integer]
counts intervals points = map (countingQuery segmentTree) points
    segmentTree = fromList intervals

in the GHC interpreter (6.10.3), my interactions look as such

*Stabbing.SegmentTree> counts [(4, 5)] [3]
*Stabbing.SegmentTree> fromList [(4, 5)]

    No instance for (SegmentTree-0.2:Data.SegmentTree.Measured.Measured

(SegmentTree-0.2:Data.SegmentTree.Interval.Interval t) t1)
      arising from a use of `fromList' at <interactive>:1:0-16
    Possible fix:
      add an instance declaration for
         (SegmentTree-0.2:Data.SegmentTree.Interval.Interval t) t1)
    In the expression: fromList [(4, 5)]
    In the definition of `it': it = fromList [(4, 5)]

As you can see, "fromList intervals" is a sub-expression of counts,
but when I try to evaluate a similar expression at the interpreter, I
get an error. Does anyone know what the problem is? This is not the
"No instance for (Show ..." error that I'm used to.

Ogechi Nnadi.

More information about the Beginners mailing list