[Haskell-cafe] Practical use of Stream's monad instance?

Olaf Klinke olf at aatal-apotheke.de
Mon Jul 11 20:10:43 UTC 2016


As someone else on this list whose name I don't recall put it, there is no 
choice on whether to make Stream a monad or not. It simply _is_ a monad. 
Anyone with some CS education hearing 'diagonal of inifinite list of 
infinite lists' should immediately think of Georg Cantor.

import Data.Stream
import Data.Ratio

type Real = Stream Rational
-- approximate a real number by an ascending stream
-- of lower bounds.

supremum :: Stream Real -> Real
supremum  = join
-- If a stream of reals is index-wise ascending,
-- the monad instance for Stream computes its supremum.
-- Use this e.g. to compute any mathematical quantity
-- defined as a supremum.

-- Olaf


More information about the Haskell-Cafe mailing list