Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Felix Mulder
@felixmulder
that sounds super hairy
Fabio Labella
@SystemFw
I don't know if the same holds for Monaderror though
Felix Mulder
@felixmulder
What do you think the risk is of making MonadError / ApplicativeError contravariant in E?
Fabio Labella
@SystemFw
Just that there were experiments with typeclasses and variance in the early days of scalaz, and they ended up with scrapping variance from data types as well :joy:
I can't reason about variance like that without pen paper and time
But you should definitely try it out and see
The underlying monad error problem is super important IMHO
Felix Mulder
@felixmulder
I'll just go to twitter and tag people -- maybe someone remembers
:+1:
I'll be the battering ram
Rob Norris
@tpolecat
Stephen Compall (S11001001) is the person to talk to. He has thought more about variance than anyone else over there I think.
The big problem was with things like trait Functor[F[+_]]
Felix Mulder
@felixmulder
@tpolecat - thanks Rob, I'll try to get a hold of him!
Emily Pillmore
@emilypi
hola, hombres
Rob Norris
@tpolecat
hi
Luka Jacobowitz
@LukaJCB
Hola!
Oleg Pyzhcov
@oleg-py
@felixmulder I'm actually working on a library that among other things lets you derive MonadError[F, E] given MonadError[F, Throwable] and E <: Throwable :smile:
Fabio Labella
@SystemFw
@oleg-py heh, wanted to mention mews but wasn't sure if you had tackled MonadErroryet
Oleg Pyzhcov
@oleg-py
I'm actually getting close to first release, just need to add more tests and law-checks :smile:
Fabio Labella
@SystemFw
nice
long term it should be in cats-mtl if it works out, you know what I think :)
Oleg Pyzhcov
@oleg-py
I've also added stuff from cats-effect so I can get rid of some StateTs :smile:
Felix Mulder
@felixmulder
@oleg-py -- cool! Gonna have a look at what you've been up to :)
Luka Jacobowitz
@LukaJCB
We need to overhaul the cats-mtl docs, I think most people are really confused by things like MonadLayerControl, when they don’t even need it at all, and should only use ApplicativeAsk, MonadState et al
Yuriy Badalyantc
@LMnet
Hi! Why cats contains Order typeclass when we have Ordering in the standart library?
felher
@felher
Hey folks. In the introductionary FP course I'm giving we are currently working our way through monads. The theoretical groundwork has been done ( operations and laws ) and it's time to go through a few monads as examples and see how and when to use them. They have already seen Option,Either, and State (and, kind of, List). I'd like to do three more examples. What monads would you suggest? Currently I'm thinking about Reader and Writer.
Andi Miller
@andimiller
I'd probably go for Eval or IO
Fabio Labella
@SystemFw
@felher Reader is not super interesting (ReaderT/Kleisli is, but that's a transformer), but I'd do it anyway . I'd go for List a bit more (behaves "weirdly" which is good to break false assumptions, and prepares you for fs2.Stream), and more importantly IO
however IO requires some subtlety when teaching it, so you might want to make sure they know how to write code with algebras first
and by that I mean code that doesn't use any specific details of the datatypes they're using, but only the algebras defined for them
for example, write code on State without using s => (a, s), but only the combinators
the reason for that is that you want them to get used to IO as an opaque entity imho
Fabio Labella
@SystemFw
I have other examples but it kinda depends on whether you want to focus on how to use monadic abstractions, or how to implement them. Most literature focuses on implementing them on one hand, or in "real world examples" without much explanations on the other, whereas I think developing the sort of thinking that lets you write code using algebras only is very important, and not necessarily always explained well.
Emily Pillmore
@emilypi
@SystemFw Ed just came up with an interesting use for Reader using classy lenses. It's really cool ;)
Oleg Pyzhcov
@oleg-py
@emilypi link? :)
felher
@felher
I think IO/Eval might be a bit too hard just now. Most of them have never done any functional programming until a few weeks ago and now have only had 6 or so lectures to take it in. My goal is to provide a 'intermediate' FP lecture next semester in which IO/Eval would be taught.
@SystemFw could you give an example of what you mean when you say List behaves weirdly?
Fabio Labella
@SystemFw
@emilypi link?
@felher yeah, in that case fair enough
well, weirdly was in quotes
but one example would be the intuition that *> means "and then"

State , check
IO, check

Ok the intuition holds...

List(1,2,3) *> List(4, 5, 6) <--- intuition breaks
again, fs2.Stream behaves like List in many respects so this is a good exercise regardless
felher
@felher
Oh, that's a great example!
Fabio Labella
@SystemFw
the instances for (-> a) (Reader) are also useful for breaking wrong intuitions / expanding one's mind, but they work better in Haskell
Emily Pillmore
@emilypi
@SystemFw when the Lambdaconf vids come out, look for it. I don’t think he’s posted slides, but you could ask him
it was effectively managing logging states using reader + pprism and plens
as opposed to the usual StateT-type solution
Fabio Labella
@SystemFw

Most literature focuses on implementing them on one hand, or in "real world examples" without much explanations on the other, whereas I think developing the sort of thinking that lets you write code using algebras only is very important, and not necessarily always explained well

@felher this really matters to me so I want to expand a bit. Let's take State as an example. In most cases books/tutorial fall in two categories:

  • "let's develop a web server where each request has a request context, to do this we can use State from cats, which has amodify function that we can use in a for comprehension. Don't worry about how it works now...[proceeds with concrete example]"
  • "Abstracting over state can be done with a => (a, s) where each function gets a new copy of the State. If we write down a couple of example we can see that it fits the Monad abstraction. Let's write the instance for Monad"

Obviously they are both useful in different respects, however there are drawbacks:

  • The first approach is good to break the ice/show you that you can write real code in FP, but it doesn't give a lasting understanding imho. You need to understand the foundations.
  • The second is good at explaining State, but it doesn't necessarily give you transferable skills that you can use with other abstractions for which you don't know the internal representation. A typical example where this breaks is when introducing IO.

I like to use a third approach. After having explained what the main algebras bring to the table (Functor lifts 1-arg functions, Applicative lifts n-ary functions, Monad gives you context sensitivity), I present State like this:

State is a datatype representing computations that describe modifications to a value, with the following algebra:

trait State[S, A] // S state, A output
object State {
   def get[S]: State[S, S]
   def set[S](s: S): State[S, Unit]

   implicit def m: Monad[State[S, ?]] // stress that this implies Functor and Applicative
}

and then you have them write programs in this "language", without knowing anything about the internal representation, but only the State algebra (get, set, what the type means, any laws, the monad instance). After they manage to use it like that, you can explain how it's implemented (typically you'll go back and forth a few times in real life). The advantage is that this is aimed to instill the sort of algebraic thinking that is not only one of the biggest advantages of FP, but also necessary when you deal with opaque/complex abstractions like IO or Stream

@emilypi right, the thing with local, I'm been waiting for the talk for a while. That's still ReaderT though I think?