Skip to main content

Home/ Haskell/ Contents contributed and discussions participated by Xiaobin Huang

Contents contributed and discussions participated by Xiaobin Huang

Xiaobin Huang

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

  • 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.
1 - 0 of 0
Showing 20 items per page