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.
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 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