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

2009-01-19 Thread S. Doaitse Swierstra


On 17 jan 2009, at 22:22, Derek Elkins wrote:


On Thu, 2009-01-15 at 13:40 +0100, Apfelmus, Heinrich wrote:

Eugene Kirpichov wrote:

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


Oops. That's because my assertion

  show . read = id

is wrong. We only have

  read . show  = id
  show . read = id  (in the less defined than sense)


No, you only have
read . show = id which often doesn't hold in practice.
show . read /= id


You do not even have that; the read may remove surplus parentheses  
which will not be reinserted by the show.


 Doaitse





Assuming the first identity holds, you do of course have show . read .
show = show and this probably holds even in most cases where read .  
show

= id does not hold.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2009-01-19 Thread Derek Elkins
On Mon, 2009-01-19 at 22:12 -0500, S. Doaitse Swierstra wrote:
 On 17 jan 2009, at 22:22, Derek Elkins wrote:
 
  On Thu, 2009-01-15 at 13:40 +0100, Apfelmus, Heinrich wrote:
  Eugene Kirpichov wrote:
  Well, your program is not equivalent to the C++ version, since it
  doesn't bail on incorrect input.
 
  Oops. That's because my assertion
 
show . read = id
 
  is wrong. We only have
 
read . show  = id
show . read = id  (in the less defined than sense)
 
  No, you only have
  read . show = id which often doesn't hold in practice.
  show . read /= id
 
 You do not even have that; the read may remove surplus parentheses  
 which will not be reinserted by the show.
 
   Doaitse
 

My notation is show . read is not less than or equal to id.  That covers
that case.  The particular example I was thinking of was actually simply
whitespace.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2009-01-17 Thread Derek Elkins
On Thu, 2009-01-15 at 13:40 +0100, Apfelmus, Heinrich wrote:
 Eugene Kirpichov wrote:
  Well, your program is not equivalent to the C++ version, since it
  doesn't bail on incorrect input.
 
 Oops. That's because my assertion
 
show . read = id
 
 is wrong. We only have
 
read . show  = id
show . read = id  (in the less defined than sense)

No, you only have
read . show = id which often doesn't hold in practice.
show . read /= id

Assuming the first identity holds, you do of course have show . read .
show = show and this probably holds even in most cases where read . show
= id does not hold.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2009-01-15 Thread Apfelmus, Heinrich
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@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2009-01-15 Thread Eugene Kirpichov
Well, your program is not equivalent to the C++ version, since it
doesn't bail on incorrect input.

2009/1/15 Apfelmus, Heinrich apfel...@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@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2009-01-15 Thread Apfelmus, Heinrich
Eugene Kirpichov wrote:
 Well, your program is not equivalent to the C++ version, since it
 doesn't bail on incorrect input.

Oops. That's because my assertion

   show . read = id

is wrong. We only have

   read . show  = id
   show . read = id  (in the less defined than sense)


Regards,
H. Apfelmus

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2009-01-15 Thread Bulat Ziganshin
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 apfel...@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@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


-- 
Best regards,
 Bulatmailto:bulat.zigans...@gmail.com

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe