[Haskell-cafe] warning - Euler problem spoiler enclosed

Artyom Kazak artyom.kazak at gmail.com
Wed May 4 17:18:27 CEST 2011


Barbara Shirtcliff <barcs at gmx.com> писал(а) в своём письме Wed, 04 May  
2011 16:41:07 +0300:

>> Also, note that "lexOrder s@[_] = [s]" is nicer than "lexOrder s |
>> length s == 1 = [s]".
>
> I agree that that initial version was a little clumsy, but your  
> suggestion doesn't really seem to work:
>
>
> lexOrder :: [Char] -> [[Char]]
> lexOrder s@[_] = s
> lexOrder s =
>          concat $ map (\n -> h n) [0..((length z) - 1)]
>          where z = sort $ nub s
>                h :: Int -> [String]
>                h n = map (z!!n :) $ lexOrder $ filter (\c -> lexI c z /=  
> n) z
>
>
> Euler.hs:8:18:
>     Couldn't match expected type `[Char]' with actual type `Char'
>     Expected type: [[Char]]
>       Actual type: [Char]
>     In the expression: s
>     In an equation for `lexOrder': lexOrder s@[_] = s

It actually works, you have forgotten square brackets: "lexOrder s@[_] =  
[s]   --not s!".



More information about the Haskell-Cafe mailing list