[Haskell-beginners] Return a Foldable instance

Federico Mastellone fmaste at gmail.com
Wed May 4 03:31:39 CEST 2011


Hi,

I want to make a function that returns a Foldable instance, briefly,
something like this:

import Data.Foldable

test :: Foldable f => f Int
test = [1,2,3,4]

But I get this error:

    Couldn't match expected type `f' against inferred type `[]'
        `f' is a rigid type variable bound by
            the type signature for `test' at Test.hs:3:17
    In the expression: [1, 2, 3, 4]
    In the definition of `test': test = [1, 2, 3, ....]

How can I make a function like the one above?

I'm creating different implementations of a multimap, using a Set and
a [], and instead of providing functions getValuesList and
getValuesSet that return a [] and a Set respectively I want to provide
a more generic one, getValues that returns a Foldable instance.

Thanks!!!

-- 
Federico Mastellone
Computer Science Engineer - ITBA
".. there are two ways of constructing a software design: One way is
to make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."

Tony Hoare, 1980 ACM Turing Award Lecture.



More information about the Beginners mailing list