Skip to main content

Home/ Haskell/ 'Cannot justify constraints in explicitly typed binding ', Hugs complained.
Xiaobin Huang

'Cannot justify constraints in explicitly typed binding ', Hugs complained. - 10 views

started by Xiaobin Huang on 14 Nov 08
  • Xiaobin Huang
     
    hi all,

    I'm new to Haskell.

    I wrote a permutation prog.

    permutation [] = [[]]
    permutation seq = foldr (++) [] (map appendEachTo seq)
    where appendEachTo i = (map (i:) (permutation (filter (i/=) seq)))
    It works.

    but I don't know how to give the type of 'permutation'.

    I wrote 'permutation::[a]->[[a]]', Hugs complain that

    *** Expression : permutation
    *** Type : [a] -> [[a]]
    *** Given context : ()
    *** Constraints : Eq a

    I think I must miss something when reading the tutorial.

    any help will be appreciated.
  • Xiaobin Huang
     
    Now I know, it should be 'permutation :: Eq a => [a]->[[a]]'.

    Xiaobin Huang wrote:
    > hi all,
    >
    > I'm new to Haskell.
    >
    > I wrote a permutation prog.
    >
    > permutation [] = [[]]
    > permutation seq = foldr (++) [] (map appendEachTo seq)
    > where appendEachTo i = (map (i:) (permutation (filter (i/=) seq)))
    > It works.
    >
    > but I don't know how to give the type of 'permutation'.
    >
    > I wrote 'permutation::[a]- >[[a]]', Hugs complain that
    >
    > *** Expression : permutation
    > *** Type : [a] - > [[a]]
    > *** Given context : ()
    > *** Constraints : Eq a
    >
    > I think I must miss something when reading the tutorial.
    >
    > any help will be appreciated.

To Top

Start a New Topic » « Back to the Haskell group