[Haskell-cafe] warning - Euler problem spoiler enclosed

Barbara Shirtcliff barcs at gmx.com
Wed May 4 18:12:20 CEST 2011


On May 4, 2011, at 9:18 AM, Artyom Kazak wrote:

> 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