Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
felher
@felher
True. I don't think it's too much of a problem, though. The students will be happy if there is something they can grasp completely and where they have a glue as to how the exam at the end of the semester might look like.
Fabio Labella
@SystemFw
ah, this is in a properly academic setting
fair enough, I've only taught in industry :)
Christopher Davenport
@ChristopherDavenport
Exam Season - PagerDuty
Atleast that’s how I see it. If I have no bugs, I sleep soundly.
Emily Pillmore
@emilypi
In Haskell at least, I find myself using it implicitly often
Less so consciously, more arrows in general
Fabio Labella
@SystemFw
@emilypi I'm not talking in general, just about the fairly specific example of teaching algebras like above. With State only you can have them write quite a few interesting programs, with Reader less so (unless you have ReaderT). Btw my favourite non-obvious use case is using Reader to write shapeless typeclass instances that depend on a runtime value
Emily Pillmore
@emilypi
Ah yeah
Taleb Zeghmi
@talebzeghmi

Hi,
Playing with introduction code http://47deg.github.io/fetch/docs.html#introduction-0

// type Fetch[A] = cats.free.Free[fetch.FetchOp, A] 
def getUser(id: UserId): Fetch[User] = Fetch(id)

for {
  x: User <- getUser(1)
} yield s"${x.id} ${x.username}”

Produces following error:
Error:(105, 23) value filter is not a member of fetch.Fetch[User]

Thoughts on how to get around this?

Taleb Zeghmi
@talebzeghmi
Why is it trying to call withFilter?
Emily Pillmore
@emilypi
because for comprehensions are implemented poorly.
every time you have a predicate on your type like : Type or if foo, it calls withFilter
Oleg Pyzhcov
@oleg-py
or a pattern like (a, _) <- something
basically at the left hand side to the arrow, anything but a simple name is a withFilter call
Emily Pillmore
@emilypi
you can get around this usually by defining the syntax for your type and writing the withFilter :: MonadError f e => (a -> Bool) -> f a -> f a function yourself, but honestly you should probably just have @oleg-py’s better for on all the time anyway (along with kind projectors or pascal)
Taleb Zeghmi
@talebzeghmi
it seems that’s forcing me to switch from Gradle to sbt, or have to exclude : Type in for comprehensions...
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