[Haskell-cafe] Re: Haskell and C++ program

Bulat Ziganshin bulat.ziganshin at gmail.com
Thu Jan 15 07:53:20 EST 2009


Hello Eugene,

Thursday, January 15, 2009, 3:27:59 PM, you wrote:

but at least "length.map show" is eq to length :)

> Well, your program is not equivalent to the C++ version, since it
> doesn't bail on incorrect input.

> 2009/1/15 Apfelmus, Heinrich <apfelmus at quantentunnel.de>:
>> Jonathan Cast wrote:
>>>   reverseDouble =
>>>         unlines
>>>       . intro
>>>       . map show
>>>       . reverse
>>>       . map (read :: String -> Double)
>>>       . takeWhile (/= "end")
>>>       . words
>>>     where
>>>       intro l =
>>>         ("read " ++ show (length l) ++ " elements") :
>>>         "elements in reversed order" :
>>>         l
>>
>> This can be simplified to
>>
>>  ... . map show . reverse . map read . ...
>>
>>  = { map f . reverse = reverse . map f }
>>
>>  ... . reverse . map show . map read . ...
>>
>>  = { map f . map g = map (f . g) }
>>
>>  ... . reverse . map (show . read) . ...
>>
>>  = { show . read = id }
>>
>>  ... . reverse . map id . ...
>>
>>  = { map id = id }
>>
>>  ... . reverse . ...
>>
>> In other words,
>>
>>  reverseDouble =
>>    unlines. intro . reverse . takeWhile (/= "end") . words
>>    where
>>      intro xs =
>>        ("read " ++ show (length xs) ++ " elements") :
>>        "elements in reversed order" :
>>        xs
>>
>> And the doubles disappeared completely. :)
>>
>>
>> Regards,
>> H. Apfelmus
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe


-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Haskell-Cafe mailing list