[Haskell-cafe] Practical use of Stream's monad instance?
conal at conal.net
Wed Jul 20 13:50:43 UTC 2016
As Tom hinted, Stream is isomorphic to function-from-Nat (Peano/lazy
natural numbers), being the memoized (trie) representation of such
functions. The Stream Monad instance corresponds to the function-from-a
Monad ("reader") instance, so all such trie Monad instances are useful
wherever we want to work monadically with functions but want memoization.
I like Olaf's example use as well: 'fmap not . join' constructs a stream of
binary representations of numbers in [0,1] that disagrees with every
element of any given enumeration of such numbers. A very terse
demonstration of a profoundly important mathematical discovery.
On Tue, Jul 12, 2016 at 4:10 AM, Petr Pudlák <petr.mvd at gmail.com> wrote:
> Indeed, the question is not wherever it's a monad or not, just to what
> extent is the monad useful.
> Dne po 11. 7. 2016 22:08 uživatel Olaf Klinke <olf at aatal-apotheke.de>
>> 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
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe