On the Squeak Slack, @asarch asked "Are there monads in Squeak?"
My answer was:
Tricky question. Monads are a kind of design pattern reflecting a formal mathematical structure. Languages with static type systems are able to enforce some (but usually not all) of the mathematical monad laws; in Smalltalk, the type system is not strong enough to enforce any monad laws. So, monads do appear in Smalltalk in two ways: implicitly, in that theoretically every expression is "in the IO monad"; and explicitly, in examples such as the API on class Promise. Squeak's Promise class implements monadic operations and honours the monad laws.
So TL;DR is "yes, but..." :-)
Cheers, Tony
Hi Tony,
On Mon, Aug 1, 2022 at 1:48 AM Tony Garnock-Jones tonyg@leastfixedpoint.com wrote:
On the Squeak Slack, @asarch asked "Are there monads in Squeak?"
My answer was:
Tricky question. Monads are a kind of design pattern reflecting a formal mathematical structure. Languages with static type systems are able to enforce some (but usually not all) of the mathematical monad laws; in Smalltalk, the type system is not strong enough to enforce any monad laws. So, monads do appear in Smalltalk in two ways: implicitly, in that theoretically every expression is "in the IO monad"; and explicitly, in examples such as the API on class Promise. Squeak's Promise class implements monadic operations and honours the monad laws.
I'd love to read a definition of the monad laws in plain English. I think I understand promises perfectly well. I've never understood what a monad is. I'm unable to think algebraically very effectively but can think visually (for example I didn't understand the fourier transform algebraically (the double integral formulation), but understand it perfectly well as an infinite set of infinite integrals of the products of a sine wave with an arbitrary waveform (itself composed of sine waves)). So if you can explain monads without recourse to algebra (but as much recourse to Smalltalk as you like) then you have my full attention.
So TL;DR is "yes, but..." :-)
Cheers, Tony
_,,,^..^,,,_ best, Eliot
correct me if i am wrong but
Association class>>return: anObject ^( self new value: anObject ) Association>>=<< aOneInputValua ^( self class return:( aOneInputValua value:( self value ) ) )
where ( aOneInputValua respondsTo:#value: )=true
or Association class>>inClass:c return: anObject ^( self key:c value: anObject ) Association>>=<< a2InputValua ^( self class inClass:( self key )return:( aOneInputValua value:( self key )value:( self value ) ) ) “where aOneInputValua uses its first input which is aClass to do some kind of runtime type checking or like or maybe more like” Association class>>inClass:c return: anObject ^( self key:c value: anObject ) Association>>=<< a1InputValua ^( self class inClass:( self key )return:( a1InputValua value:( ( ( self value )isKindOf:( self key ) ) ifTrue:[ self value ]ifFlase:[ self Error:’wrong type’ ] ) ) )
you see the thing about Haskell is that it is completely lazy so there is no evaluation ordering that can be counted on so monads are a way to impose an execution order via function composition like ( h value:( g value:( f value: x ) ) ) forces f to be done first and h last and g second
but Smalltalk is not lazy , so there is a runtime ordering , so maybe Smalltalk can get an equivalent functionality out of just composing one input valua which is just composing one input functions , unless you want to insist on the >>isKindOf: type checking
On Wed, Aug 3, 2022 at 15:18 Eliot Miranda eliot.miranda@gmail.com wrote:
Hi Tony,
On Mon, Aug 1, 2022 at 1:48 AM Tony Garnock-Jones < tonyg@leastfixedpoint.com> wrote:
On the Squeak Slack, @asarch asked "Are there monads in Squeak?"
My answer was:
Tricky question. Monads are a kind of design pattern reflecting a formal mathematical structure. Languages with static type systems are able to enforce some (but usually not all) of the mathematical monad laws; in Smalltalk, the type system is not strong enough to enforce any monad laws. So, monads do appear in Smalltalk in two ways: implicitly, in that theoretically every expression is "in the IO monad"; and explicitly, in examples such as the API on class Promise. Squeak's Promise class implements monadic operations and honours the monad laws.
I'd love to read a definition of the monad laws in plain English. I think I understand promises perfectly well. I've never understood what a monad is. I'm unable to think algebraically very effectively but can think visually (for example I didn't understand the fourier transform algebraically (the double integral formulation), but understand it perfectly well as an infinite set of infinite integrals of the products of a sine wave with an arbitrary waveform (itself composed of sine waves)). So if you can explain monads without recourse to algebra (but as much recourse to Smalltalk as you like) then you have my full attention.
So TL;DR is "yes, but..." :-)
Cheers, Tony
_,,,^..^,,,_ best, Eliot
probably Association class>>inClass:c return:anObject ^( ( anObject isKindOf:c ) ifTrue:[ self key:c value:anObject ] itFalse:[ self error:’wrong type’ ] ) would be the best place to do the type check so now Associations are Monads or Association subClass:#Monad or whatever so then Association>>=<< a1InputValua ^( self class inClass:( self key )return:( a1InputValua value:( self value ) ) )
On Wed, Aug 3, 2022 at 22:53 Kjell Godo squeaklist@gmail.com wrote:
correct me if i am wrong but
Association class>>return: anObject ^( self new value: anObject ) Association>>=<< aOneInputValua ^( self class return:( aOneInputValua value:( self value ) ) )
where ( aOneInputValua respondsTo:#value: )=true
or Association class>>inClass:c return: anObject ^( self key:c value: anObject ) Association>>=<< a2InputValua ^( self class inClass:( self key )return:( aOneInputValua value:( self key )value:( self value ) ) ) “where aOneInputValua uses its first input which is aClass to do some kind of runtime type checking or like or maybe more like” Association class>>inClass:c return: anObject ^( self key:c value: anObject ) Association>>=<< a1InputValua ^( self class inClass:( self key )return:( a1InputValua value:( ( ( self value )isKindOf:( self key ) ) ifTrue:[ self value ]ifFlase:[ self Error:’wrong type’ ] ) ) )
you see the thing about Haskell is that it is completely lazy so there is no evaluation ordering that can be counted on so monads are a way to impose an execution order via function composition like ( h value:( g value:( f value: x ) ) ) forces f to be done first and h last and g second
but Smalltalk is not lazy , so there is a runtime ordering , so maybe Smalltalk can get an equivalent functionality out of just composing one input valua which is just composing one input functions , unless you want to insist on the >>isKindOf: type checking
On Wed, Aug 3, 2022 at 15:18 Eliot Miranda eliot.miranda@gmail.com wrote:
Hi Tony,
On Mon, Aug 1, 2022 at 1:48 AM Tony Garnock-Jones < tonyg@leastfixedpoint.com> wrote:
On the Squeak Slack, @asarch asked "Are there monads in Squeak?"
My answer was:
Tricky question. Monads are a kind of design pattern reflecting a formal mathematical structure. Languages with static type systems are able to enforce some (but usually not all) of the mathematical monad laws; in Smalltalk, the type system is not strong enough to enforce any monad laws. So, monads do appear in Smalltalk in two ways: implicitly, in that theoretically every expression is "in the IO monad"; and explicitly, in examples such as the API on class Promise. Squeak's Promise class implements monadic operations and honours the monad laws.
I'd love to read a definition of the monad laws in plain English. I think I understand promises perfectly well. I've never understood what a monad is. I'm unable to think algebraically very effectively but can think visually (for example I didn't understand the fourier transform algebraically (the double integral formulation), but understand it perfectly well as an infinite set of infinite integrals of the products of a sine wave with an arbitrary waveform (itself composed of sine waves)). So if you can explain monads without recourse to algebra (but as much recourse to Smalltalk as you like) then you have my full attention.
So TL;DR is "yes, but..." :-)
Cheers, Tony
_,,,^..^,,,_ best, Eliot
so what is the use of a Monad anyway if you are not lazy is my question
well it is supposed to isolate state changes ? or simulate state or what is it
you’ve got the state Monad so every time you are going to mutate state you stop short ? you do not mutate the state no you make a new state like consing a new cons cell onto a list which is not state or something and you return that new cons cell so every time you would have mutated the state you do not mutate the state no you do the state Monad shuffle instead
but often in the GUI you want the dependents to get the latest value of a variable and you don’t care about the old value or well it’s confusing
so i am drawn to this whole Monad idea maybe somehow it simplifies or something i feel like maybe it does but when i look i can’t really see it i can’t really see why if you are not lazy i want to see it but i keep coming up short
On Wed, Aug 3, 2022 at 23:17 Kjell Godo squeaklist@gmail.com wrote:
probably Association class>>inClass:c return:anObject ^( ( anObject isKindOf:c ) ifTrue:[ self key:c value:anObject ] itFalse:[ self error:’wrong type’ ] ) would be the best place to do the type check so now Associations are Monads or Association subClass:#Monad or whatever so then Association>>=<< a1InputValua ^( self class inClass:( self key )return:( a1InputValua value:( self value ) ) )
On Wed, Aug 3, 2022 at 22:53 Kjell Godo squeaklist@gmail.com wrote:
correct me if i am wrong but
Association class>>return: anObject ^( self new value: anObject ) Association>>=<< aOneInputValua ^( self class return:( aOneInputValua value:( self value ) ) )
where ( aOneInputValua respondsTo:#value: )=true
or Association class>>inClass:c return: anObject ^( self key:c value: anObject ) Association>>=<< a2InputValua ^( self class inClass:( self key )return:( aOneInputValua value:( self key )value:( self value ) ) ) “where aOneInputValua uses its first input which is aClass to do some kind of runtime type checking or like or maybe more like” Association class>>inClass:c return: anObject ^( self key:c value: anObject ) Association>>=<< a1InputValua ^( self class inClass:( self key )return:( a1InputValua value:( ( ( self value )isKindOf:( self key ) ) ifTrue:[ self value ]ifFlase:[ self Error:’wrong type’ ] ) ) )
you see the thing about Haskell is that it is completely lazy so there is no evaluation ordering that can be counted on so monads are a way to impose an execution order via function composition like ( h value:( g value:( f value: x ) ) ) forces f to be done first and h last and g second
but Smalltalk is not lazy , so there is a runtime ordering , so maybe Smalltalk can get an equivalent functionality out of just composing one input valua which is just composing one input functions , unless you want to insist on the >>isKindOf: type checking
On Wed, Aug 3, 2022 at 15:18 Eliot Miranda eliot.miranda@gmail.com wrote:
Hi Tony,
On Mon, Aug 1, 2022 at 1:48 AM Tony Garnock-Jones < tonyg@leastfixedpoint.com> wrote:
On the Squeak Slack, @asarch asked "Are there monads in Squeak?"
My answer was:
Tricky question. Monads are a kind of design pattern reflecting a formal mathematical structure. Languages with static type systems are able to enforce some (but usually not all) of the mathematical monad laws; in Smalltalk, the type system is not strong enough to enforce any monad laws. So, monads do appear in Smalltalk in two ways: implicitly, in that theoretically every expression is "in the IO monad"; and explicitly, in examples such as the API on class Promise. Squeak's Promise class implements monadic operations and honours the monad laws.
I'd love to read a definition of the monad laws in plain English. I think I understand promises perfectly well. I've never understood what a monad is. I'm unable to think algebraically very effectively but can think visually (for example I didn't understand the fourier transform algebraically (the double integral formulation), but understand it perfectly well as an infinite set of infinite integrals of the products of a sine wave with an arbitrary waveform (itself composed of sine waves)). So if you can explain monads without recourse to algebra (but as much recourse to Smalltalk as you like) then you have my full attention.
So TL;DR is "yes, but..." :-)
Cheers, Tony
_,,,^..^,,,_ best, Eliot
I'm unable to think algebraically very effectively but can think visually (for example I didn't understand the fourier transform algebraically (the double integral formulation), but understand it perfectly well as an infinite set of infinite integrals of the products of a sine wave with an arbitrary waveform (itself composed of sine waves)).
As a visual person myself, Fourier transform did only really click with me intuitively when I saw it related to epicycles. See Mathologer's video here:
https://www.youtube.com/watch?v=qS4H6PEcCCA
Stef
On Thu, Aug 4, 2022 at 01:15 Stéphane Rollandin lecteur@zogotounga.net wrote:
I'm unable to think algebraically very effectively but can think visually (for example I didn't understand the fourier transform algebraically (the double integral formulation), but understand it perfectly well as an infinite set of infinite integrals of the products of a sine wave with an arbitrary waveform (itself composed of sine waves)).
As a visual person myself, Fourier transform did only really click with me intuitively when I saw it related to epicycles. See Mathologer's video here:
https://www.youtube.com/watch?v=qS4H6PEcCCA
Stef
Thank you for that video! Really enjoyable – I knew the epicyclic explanation for how Fourier synthesis can generate a curve, but never understood Fourier analysis, how to find the factors for a given curve. I had a light bulb moment in the last part of the video where all the integrals in the infinite sum become zero except for one particular term. Beautiful!
Vanessa
It's fun indeed.
I remember making some Etoys to draw some regular waveforms...
[image: e.jpg]
On Thu, Aug 4, 2022 at 7:58 AM Vanessa Freudenberg vanessa@codefrau.net wrote:
On Thu, Aug 4, 2022 at 01:15 Stéphane Rollandin lecteur@zogotounga.net wrote:
I'm unable to think algebraically very effectively but can think visually (for example I didn't understand the fourier transform algebraically (the double integral formulation), but understand it perfectly well as an infinite set of infinite integrals of the products of a sine wave with an arbitrary waveform (itself composed of sine waves)).
As a visual person myself, Fourier transform did only really click with me intuitively when I saw it related to epicycles. See Mathologer's video here:
https://www.youtube.com/watch?v=qS4H6PEcCCA
Stef
Thank you for that video! Really enjoyable – I knew the epicyclic explanation for how Fourier synthesis can generate a curve, but never understood Fourier analysis, how to find the factors for a given curve. I had a light bulb moment in the last part of the video where all the integrals in the infinite sum become zero except for one particular term. Beautiful!
Vanessa
On Thu, Aug 4, 2022 at 9:55 AM Yoshiki Ohshima Yoshiki.Ohshima@acm.org wrote:
It's fun indeed.
I remember making some Etoys to draw some regular waveforms...
[image: e.jpg]
<3 <3 <3
Relating sine waves to square waves, triangle waves, etc, is super valuable math. Interference also relates to e.g. the uncertainty principle. An old friend of mine, who shall remain nameless, and who was actually a computational physicist, not a physicist, was a tutor at the open university in the summer when he wasn't at rutherford lab/cern. And he taught the uncertainty principle completely wrongly because he'd never understood the idea of the interference of superposed sines of different frequencies. He taught that one can not know the energy and the position of a particle at the same time. This is wrong.
If a particle is a wave, then its energy is determined by the particle's frequency. The higher the frequency the higher the energy. if it is composed of a single sine wave then we know exactly what its energy is, but we have no idea where it is sine the sine wave exists from -infinite to +infinity. If one interposes an infinite range of frequencies of sines of the same amplitude and phase they constructively interfere at one point only and destructively interfere everywhere else, the so called delta function. [Imagine two sines of different frequencies generating the sum and difference frequency beats, think bent guitar double stops, then add a third wave of a different frequency, now the beats are longer, etc, etc. This proves for example that any function can be expressed as a sum of sines, since any function can be constructed from an infinite set of delta functions]. So if a particle is a wave, then once we have a delta function we know exactly where the particle is, but we know nothing about its energy since it is composed of an infinite spread of frequencies. However, between those two extremes there are an infinite variety of possible wave packets of differing widths. The more constrained in space the particle is the more frequencies in the packet there are. The less constrained the fewer the frequencies. So we can know to some degree both the position and energy of a particule, but the more we know one the more uncertain the other becomes. And the principle falls out precisely from wave superposition.
On Thu, Aug 4, 2022 at 7:58 AM Vanessa Freudenberg vanessa@codefrau.net wrote:
On Thu, Aug 4, 2022 at 01:15 Stéphane Rollandin lecteur@zogotounga.net wrote:
I'm unable to think algebraically very effectively but can think visually (for example I didn't understand the fourier transform algebraically (the double integral formulation), but understand it perfectly well as an infinite set of infinite integrals of the
products
of a sine wave with an arbitrary waveform (itself composed of sine waves)).
As a visual person myself, Fourier transform did only really click with me intuitively when I saw it related to epicycles. See Mathologer's video here:
https://www.youtube.com/watch?v=qS4H6PEcCCA
Stef
Thank you for that video! Really enjoyable – I knew the epicyclic explanation for how Fourier synthesis can generate a curve, but never understood Fourier analysis, how to find the factors for a given curve. I had a light bulb moment in the last part of the video where all the integrals in the infinite sum become zero except for one particular term. Beautiful!
Vanessa
-- -- Yoshiki
Found your project, and it works in SqueakJS:
https://squeak.js.org/etoys/#fullscreen&document=http://www.squeakland.o...
Vanessa
On Thu, Aug 4, 2022 at 9:55 AM Yoshiki Ohshima Yoshiki.Ohshima@acm.org wrote:
It's fun indeed.
I remember making some Etoys to draw some regular waveforms...
[image: e.jpg]
On Thu, Aug 4, 2022 at 7:58 AM Vanessa Freudenberg vanessa@codefrau.net wrote:
On Thu, Aug 4, 2022 at 01:15 Stéphane Rollandin lecteur@zogotounga.net wrote:
I'm unable to think algebraically very effectively but can think visually (for example I didn't understand the fourier transform algebraically (the double integral formulation), but understand it perfectly well as an infinite set of infinite integrals of the
products
of a sine wave with an arbitrary waveform (itself composed of sine waves)).
As a visual person myself, Fourier transform did only really click with me intuitively when I saw it related to epicycles. See Mathologer's video here:
https://www.youtube.com/watch?v=qS4H6PEcCCA
Stef
Thank you for that video! Really enjoyable – I knew the epicyclic explanation for how Fourier synthesis can generate a curve, but never understood Fourier analysis, how to find the factors for a given curve. I had a light bulb moment in the last part of the video where all the integrals in the infinite sum become zero except for one particular term. Beautiful!
Vanessa
-- -- Yoshiki
Thank you!
I took the screenshot with SqueakJS but did not occur that I can share the link this way ^^;
On Thu, Aug 4, 2022 at 12:46 PM Vanessa Freudenberg vanessa@codefrau.net wrote:
Found your project, and it works in SqueakJS:
https://squeak.js.org/etoys/#fullscreen&document=http://www.squeakland.o...
Vanessa
On Thu, Aug 4, 2022 at 9:55 AM Yoshiki Ohshima Yoshiki.Ohshima@acm.org wrote:
It's fun indeed.
I remember making some Etoys to draw some regular waveforms...
[image: e.jpg]
On Thu, Aug 4, 2022 at 7:58 AM Vanessa Freudenberg vanessa@codefrau.net wrote:
On Thu, Aug 4, 2022 at 01:15 Stéphane Rollandin lecteur@zogotounga.net wrote:
I'm unable to think algebraically very effectively but can think visually (for example I didn't understand the fourier transform algebraically (the double integral formulation), but understand it perfectly well as an infinite set of infinite integrals of the
products
of a sine wave with an arbitrary waveform (itself composed of sine waves)).
As a visual person myself, Fourier transform did only really click with me intuitively when I saw it related to epicycles. See Mathologer's video here:
https://www.youtube.com/watch?v=qS4H6PEcCCA
Stef
Thank you for that video! Really enjoyable – I knew the epicyclic explanation for how Fourier synthesis can generate a curve, but never understood Fourier analysis, how to find the factors for a given curve. I had a light bulb moment in the last part of the video where all the integrals in the infinite sum become zero except for one particular term. Beautiful!
Vanessa
-- -- Yoshiki
On Thu, Aug 4, 2022 at 1:10 PM Yoshiki Ohshima Yoshiki.Ohshima@acm.org wrote:
Thank you!
I took the screenshot with SqueakJS but did not occur that I can share the link this way ^^;
Yeah it's completely undocumented (unless you read the source)
😅
Vanessa
On Thu, Aug 4, 2022 at 12:46 PM Vanessa Freudenberg vanessa@codefrau.net wrote:
Found your project, and it works in SqueakJS:
https://squeak.js.org/etoys/#fullscreen&document=http://www.squeakland.o...
Vanessa
On Thu, Aug 4, 2022 at 9:55 AM Yoshiki Ohshima Yoshiki.Ohshima@acm.org wrote:
It's fun indeed.
I remember making some Etoys to draw some regular waveforms...
[image: e.jpg]
On Thu, Aug 4, 2022 at 7:58 AM Vanessa Freudenberg vanessa@codefrau.net wrote:
On Thu, Aug 4, 2022 at 01:15 Stéphane Rollandin lecteur@zogotounga.net wrote:
I'm unable to think algebraically very effectively but can think visually (for example I didn't understand the fourier
transform
algebraically (the double integral formulation), but understand it perfectly well as an infinite set of infinite integrals of the
products
of a sine wave with an arbitrary waveform (itself composed of sine waves)).
As a visual person myself, Fourier transform did only really click with me intuitively when I saw it related to epicycles. See Mathologer's video here:
https://www.youtube.com/watch?v=qS4H6PEcCCA
Stef
Thank you for that video! Really enjoyable – I knew the epicyclic explanation for how Fourier synthesis can generate a curve, but never understood Fourier analysis, how to find the factors for a given curve. I had a light bulb moment in the last part of the video where all the integrals in the infinite sum become zero except for one particular term. Beautiful!
Vanessa
-- -- Yoshiki
-- -- Yoshiki
[image: bild.png] Fun stuff :-D Here is a version of a spirograph I made in the Etoys image a few years ago. I had the trails form in the play field move so I could make a cool graph
Best, Karl
On Thu, Aug 4, 2022 at 6:55 PM Yoshiki Ohshima Yoshiki.Ohshima@acm.org wrote:
It's fun indeed.
I remember making some Etoys to draw some regular waveforms...
[image: e.jpg]
On Thu, Aug 4, 2022 at 7:58 AM Vanessa Freudenberg vanessa@codefrau.net wrote:
On Thu, Aug 4, 2022 at 01:15 Stéphane Rollandin lecteur@zogotounga.net wrote:
I'm unable to think algebraically very effectively but can think visually (for example I didn't understand the fourier transform algebraically (the double integral formulation), but understand it perfectly well as an infinite set of infinite integrals of the
products
of a sine wave with an arbitrary waveform (itself composed of sine waves)).
As a visual person myself, Fourier transform did only really click with me intuitively when I saw it related to epicycles. See Mathologer's video here:
https://www.youtube.com/watch?v=qS4H6PEcCCA
Stef
Thank you for that video! Really enjoyable – I knew the epicyclic explanation for how Fourier synthesis can generate a curve, but never understood Fourier analysis, how to find the factors for a given curve. I had a light bulb moment in the last part of the video where all the integrals in the infinite sum become zero except for one particular term. Beautiful!
Vanessa
-- -- Yoshiki
Hi Eliot,
On 8/4/22 00:17, Eliot Miranda wrote:
I'd love to read a definition of the monad laws in plain English.
They're terribly simple: monad composition should have a left and right identity, and should be associative. That's it.
Unfortunately they're also terribly *general* :-) and I therefore have the same problem as you when it comes to grokking them in general.
I have to think about specific instances, like the "failure monad" (Maybe), which is a chain of computations, any of which can "fail", which causes the remainder of the chain to be skipped; or the "possible worlds" monad (List, or I suppose more accurately Set), which is a chain of computations, each of which can yield zero or more possible results. The chain multiplies out the possibilities, yielding a collection of possible final answers rather than just one.
Then there's the "boring monad" (Identity) which really just sequences its operations and may as well just be function composition. The "IO monad" is just Identity equipped with a few extra IO actions. The actions fall outside the monad formalism. Similar to IO, the State monad is just Identity with some get/set operations.
Erm, not sure this helps. Happy to follow up if you have questions.
Cheers, Tony
squeak-dev@lists.squeakfoundation.org