Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jan 02 23:58
    @SethTisue banned @fakubishes:nerdsin.space
  • Dec 15 2021 05:01
    som-snytt commented #12516
  • Dec 15 2021 04:38
    SethTisue edited #1312
  • Dec 15 2021 04:38
    SethTisue opened #2273
  • Dec 15 2021 04:31
    jackkoenig opened #12516
  • Dec 15 2021 04:29
    SethTisue edited #1312
  • Dec 15 2021 04:28
    SethTisue edited #1312
  • Dec 15 2021 04:27
    SethTisue labeled #9831
  • Dec 15 2021 04:27
    scala-jenkins milestoned #9831
  • Dec 15 2021 04:27
    SethTisue labeled #9831
  • Dec 15 2021 04:27
    SethTisue opened #9831
  • Dec 15 2021 03:35
    som-snytt commented #11339
  • Dec 15 2021 03:27
    som-snytt labeled #12494
  • Dec 15 2021 03:07
    SethTisue edited #1312
  • Dec 15 2021 03:07
    SethTisue edited #1312
  • Dec 15 2021 03:05
    SethTisue edited #1312
  • Dec 15 2021 03:05
    SethTisue edited #1312
  • Dec 15 2021 03:05
    SethTisue edited #1312
  • Dec 15 2021 02:58
    SethTisue edited #1312
  • Dec 15 2021 02:58
    SethTisue synchronize #1312
Fabio Labella
@SystemFw
that's the mistake made in the third explanation in your list: everything said does not refer to monads, but to effects in general. (also, "impure things in a pure language" is wrong, everything is completely, 100% pure, monads or not).
The first explanation encoded monad as an interface and not a typeclass, and therefore it cannot have unit, which means it can't be a monad (for both practical and theoretical reasons)
The second explanation in the list is the least misleading, but it's too vague and probably only useful for those who already know the concept
Arnaud Esteve
@aesteve
@dsysme re. "motivation", did you read https://cdsmith.wordpress.com/2012/04/18/why-do-monads-matter/ ?
The "The Four Horsemen of the Catapocalypse" helped me alot understanding abit of the monad thing
Fabio Labella
@SystemFw
I'm talking about general motivation for FP, not just for Monads
like, there's three aspects here, which are related but independent
Arnaud Esteve
@aesteve
@SystemFw sorry Fabio, I was referring to @dsysme comment, especially the "most tutorials just drop on you tons on details before even giving you the motivation as to why"
Fabio Labella
@SystemFw
ah, sure :)
Arnaud Esteve
@aesteve
I enjoyed reading this article, for the monad part, yes, but also on "general motivation algebra stuff" (to be intentionnaly vague)
I loved the "Quick quiz: Do computer programmers use functions?" part
it helped me realise that we cannot apply the kind of algebra I remembered from school (applications, sets, groups, rings, fields) but needed an higher level of abstraction
and from there, objects, arrows are straightforward, then come the Functor... not saying it's trivial, but definitely helps :)
Fabio Labella
@SystemFw
anyway, there's three aspects:
  • what is referential transparency, and why it matters. This is key. It's the foundational principle of pure FP, where most of its advantages comes from, and everything else comes back to this.
  • why do effects - representing computations with higher kinded types of shape F[A] (kind * -> *) - matter. This is the most neglected part, everyone's talking about "monads", in ways that generate lots of confusion. A good treatment of this helps you tremendously understanding the rest
  • why does Monad matter, as opposed to Functor, Applicative, Monoid, Arrow, and the other typeclasses. If you understand the first two points, explaining the extra power (and subsequent compositional limitations) that Monad has compared to other algebras is easy. The essence of what they give you.
also, we can apply the kind of algebra you refer to, Monoid being an example
category theory can be useful to connect things, but it's not required to become an FP expert imho
Arnaud Esteve
@aesteve
I agree :)
Arnaud Esteve
@aesteve
@SystemFw I think the "Four horsemen of the apocalypse" part of my link covers (or at least, gives motivation) about the "effects" part. Don't you think ?
Fabio Labella
@SystemFw
it does, but it's too hung up on kleisli arrows (since the kleisli category is its way of getting to monads)
it's not a bad explanation by any means
but I'm talking about things of shape F[A] as a standalone entities, as well as their relationship with typeclasses/algebras, especially the fact that algebras describe part of their behaviour, but some things are specific to each concrete datatype <-- failure to understand this leads to the "how do I get this value out of IO" fallacy
ritschwumm
@ritschwumm
Saurabh Rawat
@eklavya
is it possible at runtime to determine if there is a type class instance for some type?
the need is to have def isEffect(t: Type): Boolean = true if there is an Effect[t], at runtime
Andi Miller
@andimiller
where would you get it from?
type class resolution is always compile time because that's how we resolve implicits, afaik
Georgi Krastev
@joroKr21
Nothing is stopping you to define a type class Exists:
trait Exists[A] { def apply(): Boolean }
object Exists extends Nope {
  implicit def sure[A](implicit a: A): Exists[A] = new Exists[A] {
    def apply() = true
  }
}
trait Nope {
  implicit def nope[A]: Exists[A] = new Exists[A] {
    def apply() = false
  }
}
then you can do def isEffect[T](implicit isIt: Exists[Effect[T]]) = isIt()
Fabio Labella
@SystemFw
that's still at compile time though I think
they want it at runtime
it's the same rho issue
when rho only had Task
Andi Miller
@andimiller
rho should be able to do that at compile time
Fabio Labella
@SystemFw
you would take a type and tests at runtime if it was Task (with a TypeTag)
Andi Miller
@andimiller
I dunno why it'd need that
Fabio Labella
@SystemFw
now they need the same, but for a typeclass, and I'm not sure it's possible
it's been asked by several people several times, and still no solution :(
this is for the implementation of swagger support in rho iirc (might be wrong here)
Georgi Krastev
@joroKr21
Well you could do it for a sealed trait with shapeless, but in general that's just a really weird thing to want
And that's actually the other way around: I have a value and I want to see if the typeclass resolves for its runtime type, which is of course impossible in general.
Fabio Labella
@SystemFw
lol, I hadn't even noticed this wasn't the http4s channel
It's definitely a very very niche case
I agree it's not possible, you'd need something like TypeTag, which would need to also capture typeclass instances
OlegYch
@OlegYch
rho would do well to use a typeclass for docs
tom-Kc
@tom-Kc
  trait TagHandler {
    def success(x: Any): Unit
    def failure(reason: Throwable): Unit
  }

  abstract class StandardTagHandler(val pfAllowedStates : PartialFunction[State, Unit]) extends TagHandler {
    def sth_success(x : Any) : Unit

    def success(x : Any) : Unit =
      if (pfAllowedStates.isDefinedAt(state)) sth_success(x)
      else resetToInit(s"$this called in unallowed state $state")

    def failure(reason : Throwable) : Unit = {
      resetToInit(s"$this failed with reason : $reason")
    }
  }
this is inside a FSM class that has a state : State . i want to make this intermediate StandardTagHandlerclass so I don't keep rewriting the state check boiler plate
is this is right way to use the partialFunction? or should it be State => Boolean check or something like that
Saurabh Rawat
@eklavya
I have no idea about whether or not it was possible, so I thought I would ask the experts :P
I think the consensus is that it's not possible
Martijn Hoekstra
@martijnhoekstra
@tom-Kc State => Boolean is much better IMO. Even better would be to do your state transitions strongly typed
tom-Kc
@tom-Kc
@martijnhoekstra you are right i actually had to go with State => Boolean in the end ... the pf actually wouldnt compile because of using pf literal in the constructor ... How could I make them strongly typed?
Martijn Hoekstra
@martijnhoekstra
it depends on what your state transitions look like. If you have State1 <: State etc, you could have a class StateTransition[A, B], have the method that does a state transition from From to To take an implicit StateTransition[From, To], and have a bunch of implicit object transitionFromTo extends StateTransition[From, To] for the allowed transitions