These are chat archives for ramda/ramda

18th
Jun 2016
Tushar Mathur
@tusharmath
Jun 18 2016 04:41
:point_up: June 17, 2016 7:16 PM Ah I see, instead of MayBe we can put it inside an Array, which is clever. There is also another case that R.ap handles — https://github.com/ramda/ramda/blob/v0.21.0/src/ap.js#L30-L33 This is when it considers the applicative to be a function. What's the intuition there?
James Forbes
@JAForbes
Jun 18 2016 06:45
@tusharmath good find! I have no idea!
Valenchak
@Valenchak_twitter
Jun 18 2016 14:11
Hello
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 21:26
is there is a gitter room for ramda fantasy ?
I was interested if it is possible to get some examples of usage of the reader monad from ramda-fantasy
never-mind :smile:
just curious - is there a reason for not implementing the state monad ?
Scott Sauyet
@CrossEye
Jun 18 2016 21:39
People have been talking about it. I just don't think anyone's gotten around to it.
I know @scott-christopher has a PR somewhere on this. Don't recall the state of it.
I may be somewhat of a blocker on this one as I've been less convinced about the advantage of the State Monad in JS than of some of the others. But I haven't been that active in Ramda-Fantasy in any case.
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 22:15

@CrossEye thats for that !

If I am not mistaken the only difference between the reader and state monad is the fact that with state you can both read and write - but not with reader

@scott-christopher - I am not sure what this line is doing :worried:
Reader.ask.chain(env => Reader.of(configureDb(env.dbConn)));
isn't ask a function ?
but you are chaining ask ?
Scott Christopher
@scott-christopher
Jun 18 2016 23:14
@JoyKrishnaMondal - ask is just a Reader instance that provides access to the whole environment of the Reader.
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:14
how does that work ? do not you have to do .of ?
.of creates a reader instance
Reader is the class ? since its upper case
reader is the instance ?
Scott Christopher
@scott-christopher
Jun 18 2016 23:16
Reader.of = a => Reader(_ => a)
Reader.ask = Reader(a => a)
So of creates an environment from the provided value, ignoring the provided value.
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:17
what is the underscore ?
_ => a ?
o
oh
so its like I do not care ?
Scott Christopher
@scott-christopher
Jun 18 2016 23:17
The _ just represents an argument that isn't used.
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:18
oh thanks !
Denis Stoyanov
@xgrommx
Jun 18 2016 23:18
@scott-christopher @JoyKrishnaMondal like for function of/pure is () => x
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:18
yes I think
constant = 5
a = -> constant
just returns the closure value

so when you do

Reader.ask
you are just calling .of ?

Scott Christopher
@scott-christopher
Jun 18 2016 23:19
Reader is basically a data-type to model functions.
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:20
doesn't the Reader constructor call .of ?
like in Dr.Boolean's books ?
isn't of a constructor ?
so ask just calls the constructor
however of is if you want to pass a function ?
Scott Christopher
@scott-christopher
Jun 18 2016 23:22
I'm not sure how Brian constructs it in his books, but the constructor argument for a Reader should just be a function.
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:22
so Reader's constructor accepts a function , a lot like IO
Scott Christopher
@scott-christopher
Jun 18 2016 23:22
Yep
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:22
isn't Reader () - equivalent to Reader.of ?
Reader(f)
Reader.of (f)

okay
but what does this mean

Reader.ask.chain ?

shouldn't it be
Reader.ask (env).chain ?
since ask accepts an env variable
Scott Christopher
@scott-christopher
Jun 18 2016 23:25
Ask doesn't accept an env variable though. When the Reader is ready to be executed, you provide the env like in Reader.run with ramda-fantasy.
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:25
so Reader.run is similar to Future.fork ?
you pass your env to .run ?
Scott Christopher
@scott-christopher
Jun 18 2016 23:25
Reader is basically just a way to compose a bunch of functions together.
Yep, that's right.
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:26
okay I think I get that bit !
but I am still not sure what the rest of it does :(
for example Reader.chain
would flatten
Scott Christopher
@scott-christopher
Jun 18 2016 23:26
Perhaps we can walk through an example.
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:26
Reader(Reader) type
make it a single Reader Instance ?
@scott-christopher - do you use an streaming libraries ?
Denis Stoyanov
@xgrommx
Jun 18 2016 23:27
I'm not sure that in JS we need Reader monad, because we don't have normal IO
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:27
rxjs, kefir
what is the difference between normal IO and special IO :smile:
Denis Stoyanov
@xgrommx
Jun 18 2016 23:28
Reader monad is just a wrapper on Function monad
@JoyKrishnaMondal like in haskell
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:28
what is a Function monad ? :worried: Do you mean Functor ?
I only know - Maybe, IO, State, Reader
Either
Scott Christopher
@scott-christopher
Jun 18 2016 23:30
@JoyKrishnaMondal I haven't really used any of the streaming libraries in anger.
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:30
in anger ?
are you angry about something :worried:
Denis Stoyanov
@xgrommx
Jun 18 2016 23:30
@JoyKrishnaMondal no, monad for function
instance Functor ((->) r) where
    fmap = (.)

instance Applicative ((->) a) where
    pure = const
    (<*>) f g x = f x (g x)

instance Monad ((->) r) where
    f >>= k = \ r -> k (f r) r
Scott Christopher
@scott-christopher
Jun 18 2016 23:30
Sorry, just a saying to mean having used it a lot
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:30
oh :D
I though we were not happy
Scott Christopher
@scott-christopher
Jun 18 2016 23:31
haha
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:31
is that an australian thing ?
Scott Christopher
@scott-christopher
Jun 18 2016 23:31
Quite likely :D
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:32
@xgrommx you mean attaching propertiries to functions ?
either it be map, ap ?
Scott Christopher
@scott-christopher
Jun 18 2016 23:33
So the Reader and IO types (at least how we've constructed them in JS) are ways of describing Functor/Monad behaviours over functions.
Denis Stoyanov
@xgrommx
Jun 18 2016 23:33
@JoyKrishnaMondal why this code works? (fmap fmap (+)) 10 $ Just 10 :smile:
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:33
@scott-christopher you should join us at cujo/most.js maybe we can help you see the usefulness of it all ! you will like it given its close to the you program
because its Just (Just 10) ?
and you are unwrapping it twice ?
not sure :worried:
Denis Stoyanov
@xgrommx
Jun 18 2016 23:35
@JoyKrishnaMondal no, you should understand what is a functor for function
Scott Christopher
@scott-christopher
Jun 18 2016 23:35
The only real difference between Reader and IO is that Reader models a functions of r -> a, while IO is effectively specialised for () -> a.
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:36
is it different then functors for _
right, so Reader just like IO stacks a bunch of functions like Dominos ?
Denis Stoyanov
@xgrommx
Jun 18 2016 23:36
@JoyKrishnaMondal functor for function is a composition
Scott Christopher
@scott-christopher
Jun 18 2016 23:36
Not really.
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:37
and in IO you do the IO step at the end, while for reader you do the dependency injection at the end ?
Denis Stoyanov
@xgrommx
Jun 18 2016 23:37
@JoyKrishnaMondal
fmap . (+) $ x
fmap ((+) x)
fmap(x+)
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:37
what is the . operator ?
$ is compositoin
just like ramda.compose
of I think I get the first line
Denis Stoyanov
@xgrommx
Jun 18 2016 23:38
@JoyKrishnaMondal no, (.) like in ramda compose
@JoyKrishnaMondal State monad = Reader + Writer
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:42
yeah state monad is the difficult one
I am not even going to try and understand it before I understand Reader
isn't write for console.log only ?
WRITER*
Scott Christopher
@scott-christopher
Jun 18 2016 23:52
Writer is conceptually a way to log something during a computation. In practice it just keeps the logged value along with the value returned from the computation in a tuple. When something new is logged, is is joined with the existing logged value using its monoid behaviour (e.g. concat in fantasy-land terminology).
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:52
so its not exactly the state monad :D
state monad - allows you to change values and also read from them
Scott Christopher
@scott-christopher
Jun 18 2016 23:53
That's right.
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:53
@xgrommx so state monad != writer + reader
writer is also not a semigroup then if it can concat
Scott Christopher
@scott-christopher
Jun 18 2016 23:54
To make things more confusing, there is special RWS type offered in Haskell this is the combination of Reader, Writer and State in a single type.
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:54
nice :+1:
and then people wonder why there are not many haskellers
Scott Christopher
@scott-christopher
Jun 18 2016 23:55
It's not that bad if you give it some time :)
Joy Krishna Mondal
@JoyKrishnaMondal
Jun 18 2016 23:56
anyway @scott-christopher - your reader monad draft was really helpful - I am still not 100% what you are trying to say :worried: but I think with time I will get some grasp