Re: [Haskell-cafe] Practical use of Stream's monad instance?
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
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@aatal-apotheke.de> napsal:
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
Hi Petr. 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. - Conal On Tue, Jul 12, 2016 at 4:10 AM, Petr Pudlák <petr.mvd@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@aatal-apotheke.de> napsal:
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: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
participants (3)
-
Conal Elliott -
Olaf Klinke -
Petr Pudlák