These are chat archives for got-lambda/expression

9th
Nov 2016
jolod
@jolod
Nov 09 2016 10:40
@Jell Why not Elm instead of PureScript? Especially if you want to avoid the M word.
Jean-Louis Giordano
@Jell
Nov 09 2016 12:14
I want to illustrate polymorphism
I did consider Elm, but I thought that PureScript might be a bit more straightforward to tackle
mostly the point is not to sell on a language per se, mostly to be able to expose people to all possible concepts
and I want to be able to mention parametric polymorphism (along with ad-hoc polymorphism & subtyping)
and I will not talk about monads at all no :)
maybe ambitious, but depending on the crowd if I get there I want to be able to explain / demo it
Jean-Louis Giordano
@Jell
Nov 09 2016 13:09
ah... although I notice that there is no way to print to the console without using an IO monad... that's... annoying
Marco Zocca
@ocramz
Nov 09 2016 13:34
HA
Jean-Louis Giordano
@Jell
Nov 09 2016 13:35
this is hello world in purescript:
module Main where

import Prelude
import Control.Monad.Eff.Console (log)

main = log "hello world"
Control.Monad.Eff seriously?
Marco Zocca
@ocramz
Nov 09 2016 13:36
and I believe log :: String -> IO ()
or Eff ()
yeah because Eff discriminates the type of effects, such as reading from terminal or logging output
Jean-Louis Giordano
@Jell
Nov 09 2016 13:40
yeah but my mind is blown that there isn't such a thing in the prelude or something... first 2 seconds and if you want to get anything out you need to literally type Monad
Marco Zocca
@ocramz
Nov 09 2016 13:41
so it doesn't infer types by itself?
Jean-Louis Giordano
@Jell
Nov 09 2016 13:41
no the issue is that you need to import log
and log is in that namespace
or module rather
if I could write this it would be fine:
module Main where

import Prelude

main = log "hello world"
Marco Zocca
@ocramz
Nov 09 2016 13:42
ah, got it now. Well in C too you have to import stdio.h to use printf
Jean-Louis Giordano
@Jell
Nov 09 2016 13:42
I just think having Monad in the hello world is bad marketting
haskell does it better, you don't have to know or care about monads to print something out...
Marco Zocca
@ocramz
Nov 09 2016 13:43
yeah, I wonder why they broke it out into a separate module
Jean-Louis Giordano
@Jell
Nov 09 2016 13:45
I suspect they are not doing proper dead-code elimination, and are stuck to the JavaScript way of a million small module to avoid having a bloated production build...
but that's just me speculating
Marco Zocca
@ocramz
Nov 09 2016 13:46
or maybe they like a clean separation of pure and "effectful"
Jean-Louis Giordano
@Jell
Nov 09 2016 13:48
I am wrong: they are doing dead-code elimination
so then probably what you say @ocramz
I will try to setup a REPL, will keep you all updated :)
I would be very sad if I can't keep on my own promise to not bring up monads :(
Marco Zocca
@ocramz
Nov 09 2016 14:03
you don't have to explain what monads are, but if you have to use the M word just say it's a way to model effects
Jean-Louis Giordano
@Jell
Nov 09 2016 14:04
yeah... but still
Screen Shot 2016-11-09 at 15.08.17.png
Jean-Louis Giordano
@Jell
Nov 09 2016 14:09
I mean... ok I should stop ranting about beginner friendliness
Screen Shot 2016-11-09 at 15.11.24.png
I think this is what I will go for
Jean-Louis Giordano
@Jell
Nov 09 2016 14:19
ok I think I should be reconsidering my choice. Elm is much better in terms of beginner friendliness.
Marco Zocca
@ocramz
Nov 09 2016 15:07
it's even stranger that the repl doesn't even load (+)
Jean-Louis Giordano
@Jell
Nov 09 2016 15:10
what do people think? is this scary?
module Main where
import Prelude
import Control.Monad.Eff.Console (logShow)

main = logShow example where
  example = 1 + 2
vs Elm:
import Html exposing (text)

example = 1 + 2

main = text (toString example)
Marco Zocca
@ocramz
Nov 09 2016 15:26
Purescript : logShow (1 + 2) only takes one call
Jean-Louis Giordano
@Jell
Nov 09 2016 15:27
?
Marco Zocca
@ocramz
Nov 09 2016 15:27
you can get rid of the where clause
Jean-Louis Giordano
@Jell
Nov 09 2016 15:27
of course, but if I inline the example it's harder to see the actual example from the boiler plate
imho
Marco Zocca
@ocramz
Nov 09 2016 15:28
yeah ok, but this example is too small to be representative
Jean-Louis Giordano
@Jell
Nov 09 2016 15:28
I could cheat and scroll so the audience only sees example = 1 + 2
or something... I dunno
or output = 1 + 2
bad idea?
Marco Zocca
@ocramz
Nov 09 2016 15:31
uh; I guess the advantages of separating pure functions from I/O actions are seen on bigger examples. These two are so minimal that they're in fact the same thing
jolod
@jolod
Nov 09 2016 16:06
@Jell It quickly gets worse (from a beginner's perspective). Web Hello World in PureScript http://www.parsonsmatt.org/2015/10/03/elm_vs_purescript.html and in Elm http://www.parsonsmatt.org/2015/10/05/elm_vs_purescript_ii.html .
@Jell No, wrong link for Elm.
@Jell Elm is actually in the first link as well, but I missed it because it's only three lines.
jolod
@jolod
Nov 09 2016 16:18
@Jell I think showing off type classes is a bit too ambitious, but polymorphism indeed need to be address. One of the first questions I was asked when I explained FP to a Ruby programmers was "How do you do monkey patching?" ...
Magnus Therning
@magthe
Nov 09 2016 16:28
@Jell, except for the placement of 'where' they're pretty much equally friendly ;)
Jean-Louis Giordano
@Jell
Nov 09 2016 16:30
yeah people coming from other languages basically ask "how to polymorphism without OO?"
it's a very important point to adress I think
Marco Zocca
@ocramz
Nov 09 2016 16:33
@Jell fold a tree and a list with the same function : D
Jean-Louis Giordano
@Jell
Nov 09 2016 16:33
yeah, except not in Elm :(
Marco Zocca
@ocramz
Nov 09 2016 16:33
but from @jolod 's examples, Elm wins in conciseness
I think
and in "getting sh+t done quickly"
Jean-Louis Giordano
@Jell
Nov 09 2016 16:36
hum one option I did not consider is ghcjs. Is it viable?
I suspect less user friendly than PureScript
Marco Zocca
@ocramz
Nov 09 2016 16:38
The data as of last week are that 1. it still has a long boot-up time and 2. large memory footprint
jolod
@jolod
Nov 09 2016 16:48
@Jell Javascript programmers should be familiar with prototype OO, no? You can almost trivially do the same thing in Clojure with a little less nice syntax. And then you can compare with protocols, which I think are easier to understand, and are better named than typeclasses for OO programmers. So you'll be showing off two different ways of doing polymorphism in the same language.
Jean-Louis Giordano
@Jell
Nov 09 2016 16:48
yeah I'm planning to blow their mind with multi-methods
or wait, were you thinking of something else?
I just want to show how it's done in static-typed land
(maybe I'm too optimistic)
jolod
@jolod
Nov 09 2016 16:50
In static-typed land you can pass around a record with the "methods".
It's also nice that you that way get "introspection" for free if you have optional methods (i.e. in a Maybe).
If you want to be more OO and Javascript-like then you put your data in the record too.
Jean-Louis Giordano
@Jell
Nov 09 2016 16:53
that's true, but that's more how to do OO in FP than how to do polymorphism in FP?
one of the nice point of FP is to be able to have a clean split between data and behaviour imho
jolod
@jolod
Nov 09 2016 16:54
The reason is to be able to have different behavior for different data coming in though.
Sure, the point of having the data in th record was to show how to go from a Javascript style to a FP-style where you separate behavior.
jolod
@jolod
Nov 09 2016 17:01
I think there are legitimate use cases for the "class map" though. I've used it in Clojure. The problem with records (and multimethods) is that they're global. When the behavior is stored in just a map you gain a lot of flexibility and can trivially construct alternative implementations. Compare with doing newtype in Haskell for a type that has lots of instances.
Other times you need that global place, because you might not have access to the "class map" in the right places to add behavior.
Jean-Louis Giordano
@Jell
Nov 09 2016 17:15
another reason to use PureScript though if we want to look at row polymorphism?
aaaaah this is so hard
my gut feeling tells me: use the most powerful languages on the spectrum of dynamic - static
and from what I can see in the front-end that's ClojureScript & PureScript
both of them adress the expression problem in their own way
Elm is indeed more beginner friendly, but I'd rather provide knowledge on concepts than on the specifics of a language
Marco Zocca
@ocramz
Nov 09 2016 17:18
comparing languages is a bit like comparing apples and oranges. The differences are multidimensional. Just pick one you can honestly argue in favour of.
Jean-Louis Giordano
@Jell
Nov 09 2016 17:18
exactly, the point is not to compare or recommend a language
I want to show "what is the essence of FP?"
and to illustrate that FP can mean many things and covers a large spectrum
Marco Zocca
@ocramz
Nov 09 2016 17:21
the essence of FP? lambdas and typeclasses
done : D
ok, jokes aside. We also don't want to confuse the audience
honestly, I like many ideas behind PureScript but it's a bit wordy still. Elm gives me the same feeling writing HTML 1.0 in notepad gave me back then: "omg it works right away?!"
Jean-Louis Giordano
@Jell
Nov 09 2016 17:25
:p
perhaps showing Elm off would be more empowering then
PureScript might be overwhelming
especially if they leave the meetup and they try to do something on their own
in which case, Elm probably wins hands down
jolod
@jolod
Nov 09 2016 17:33
I think I will like PureScript too. I plan to rewrite an Elm thing in PureScript. I don't mind wordiness. I think import X (..) is overused in Elm.
But I think that PureScript reinforces that idea that you need a PhD to do FP.
Jean-Louis Giordano
@Jell
Nov 09 2016 17:34
yeah that's my (sad) feeling after playing with it for a few hours
the hello world is rough for beginners imho
jolod
@jolod
Nov 09 2016 17:46
@Jell I liked https://www.youtube.com/watch?v=O_kWwaghZ9U . It highlights some of the differences. I can't speak for the accuracy or quality of that talk though, since I don't know PureScript.
Jean-Louis Giordano
@Jell
Nov 09 2016 17:47
thanks for the recommendation! will have a look
Jean-Louis Giordano
@Jell
Nov 09 2016 21:34
hum... in Elm:
runtimeError = \x -> (+) == (+)
interesting
(from that video above)
Fancy Types vs Magic sounds about right. Interesting trade-offs