Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Emily Pillmore
@emilypi
well, if you type your functions appropriately, most of the time you don’t need the type annotation
Taleb Zeghmi
@talebzeghmi
@oleg-py thank you!
Rob Norris
@tpolecat
@felher @SystemFw I think Reader is at least a little bit interesting because it gives you dependency injection. When you’re first learning it’s eye-opening I think. I was impressed anyway.
I also found State’s implementation to be very eye-opening because dispelling the magic is important. That was really the one that tipped the scale for me.
Fabio Labella
@SystemFw

also found State’s implementation to be very eye-opening

Oh yeah, I'm not saying you shouldn't explain it. I'm saying that if you start with the algebra only you can also gain some more transferrable skills which are essential but never taught. After that, you can explain how State works internally

Rob Norris
@tpolecat
:+1:
felher
@felher
@tpolecat Yeah, Reader I will definitively go through. Dependency inejction with it is cool, and is the obvious use case I will explain. I think the real power comes with ReaderT. But you have to start somewhere and monad transformers are out of reach at the moment.
Fabio Labella
@SystemFw
@felher are you using scala or haskell?
for the course I mean
felher
@felher
I also think I will do Writer, and now probably List in a bit more detail since @SystemFw has suggested that.
@SystemFw The course is in Scala. Recommended reading is the red book.
Fabio Labella
@SystemFw
Nice, then I have another small exercise
felher
@felher
I have to run. But i will read it when I'm home :)
Fabio Labella
@SystemFw
this is for teaching type tetris/breaking some more assumptions
sure, it's really small anyway
isAlpha :: Char -> Bool
isNum :: Char -> Bool

isAlphaNum :: Char -> Bool
isAlphaNum = (||) <$> isAlpha <*> isNum
this is seriously mind bending at first (or at least it was for me at the time), but it improves your "follow the types" game significantly
Rob Norris
@tpolecat
@felher i did at talk at sbtb about monads that may or may not be helpful. I think parts of it worked and parts didn't.
felher
@felher
@SystemFw sorry, I meant scala. I edited my.post but I think I was too late :). Haskell wasn't an option here
@tpolecat do you have a link? I'd like to take a look in any case
Fabio Labella
@SystemFw
@felher ah, then no :P
Rob Norris
@tpolecat
Yeah here.
felher
@felher
Thanks.
Benny Thompson
@bennythomps
would someone be willing to validate my approach to writing my own type class implementation?
Fabio Labella
@SystemFw
sure
if I can
Benny Thompson
@bennythomps
it's pretty simple, so i have a trait like this:
trait Template[T] {
  def generate(t: T): Generated

  def defaults: T
}
Fabio Labella
@SystemFw
Generated is a concrete type yeah?
Benny Thompson
@bennythomps
correct
object Template {

  implicit class TemplateOps[A](a: A) {
    def generate()(implicit template: Template[A]) = {
      template.generate(a)
    }
  }

}
does that looks okay for a means to bring in an implicit into scope to use generate on an existing instance of A?
Fabio Labella
@SystemFw
that's syntax
but yeah
Benny Thompson
@bennythomps
k, my question would be, do i need another class for defaults since it doesn't take an existing instance of A?
i tried looking at pure and things but couldn't translate it
Fabio Labella
@SystemFw
how would the syntax look like for default?
Benny Thompson
@bennythomps
based on the type of A it would return a new instance of Generated
Fabio Labella
@SystemFw
you can't have syntax a.defaults because obviously there's noa
you will have to specify A manually of course
defaults[MyType]
if you do defaults it won't work since it can't know about A
Benny Thompson
@bennythomps
so do i need a type on defaults and that's it?
Fabio Labella
@SystemFw
in terms of making it prettier, you can do it two ways
either you add def apply[A](implicit ev: Template[A]): Template[A] = ev to the object
that way you can do Template[MyType].defaults
or you add a function def defaults[A](implicit ev: Template[A]): A = ev.defaults to the object (in addition to the one in the typeclass`
Benny Thompson
@bennythomps
i like that
Fabio Labella
@SystemFw
and that lets you do Template.defaults[MyType]
Benny Thompson
@bennythomps
i prefer the former, so i'll probably go that way, but that was exactly what i needed, thank you once again @SystemFw !
Fabio Labella
@SystemFw
np