These are chat archives for typelevel/cats

20th
Mar 2015
Miles Sabin
@milessabin
Mar 20 2015 01:55
@non (or anyone who can suggest something) ... how would I rework this: https://github.com/milessabin/demo-scaladayssf-2015/blob/master/src/main/scala/scaladays/scaladays.scala#L538 using Fold?
TailRec has the infrastructure that supports flatMap, but Fold doesn't appear to.
Michael Pilquist
@mpilquist
Mar 20 2015 12:21
i’ve been recording talks on functional type classes — doesn’t cover cats directly, but there’s much overlap: https://www.youtube.com/playlist?list=PLFrwDVdSrYE6dy14XCmUtRAJuhCxuzJp0
InTheNow
@InTheNow
Mar 20 2015 13:39
@mpilquist being busy, etc, I've just watched the first five minutes - but I can tell that you have obviously nailed this. Congratulations!! And of course, yes, I shall be watching the rest:)
Michael Pilquist
@mpilquist
Mar 20 2015 15:06
@InTheNow thanks! feedback appreciated :)
Rob Norris
@tpolecat
Mar 20 2015 16:43
So, rolling back the scroll a month or two ... the idea of indexing a Set on the singleton type of its Order instance doesn't work because instances constructed inductively with a def (like Order[(Int, (String, String))] don't have stable identifiers. So i'm back to thinking that global unique instances must be the general rule. But perhaps local instances whose presence cannot be observed are ok in the same way an unobservable var is ok. If I want to sort a list backwards, I'm fine inverting the default ordering.
Anyway just wanted to point that out for the record.
Erik Osheim
@non
Mar 20 2015 17:20
@milessabin we can add a flatMap to Fold[A] -- there's nothing that prevents it.
Cody Allen
@ceedubs
Mar 20 2015 17:21
@non you just made a guest appearance in Miles' Shapeless workshop via a Gitter notification ;)
Mike (stew) O'Connor
@stew
Mar 20 2015 17:22
why, btw, are we keeping map/flatMap out of Lazy?
Erik Osheim
@non
Mar 20 2015 17:23
@stew yes, as part of the great compromise that we negotiated over allowing people to lawfully call .value
but i don't think Fold[A] has the same issues.
@ceedubs hahaha awesome :)
i should have said something funnier
Adelbert Chang
@adelbertc
Mar 20 2015 17:23
@ceedubs wish i was there :(
Mike (stew) O'Connor
@stew
Mar 20 2015 17:26
@non what is the issue with calling .value?
Erik Osheim
@non
Mar 20 2015 17:27
@stew there was an argument that use of Lazy[A] is a requirement for the value to "stay" lazy.
which would make calling .value something like .unsafePerformValue
(but requiring strictly monadic use of Lazy[A] defeats the point of using it as a replacement for by-name params in APIs)
Rob Norris
@tpolecat
Mar 20 2015 17:28
a problem was that it could become less lazy via map and flatMap ... the flavor of laziness you ask for on construction isn't preserved
Erik Osheim
@non
Mar 20 2015 17:28
anyway, the compromise we ended up with (suggested by @tpolecat i think) was to avoid putting .map or .flatMap methods on Lazy[A] to signal that it is a "low-level" piece of machinery
Mike (stew) O'Connor
@stew
Mar 20 2015 17:28
you can write map without calling .value, right?
Rob Norris
@tpolecat
Mar 20 2015 17:29
yeah my proposal was to just chop off the discussion at the knees by saying it's not an abstraction
Mike (stew) O'Connor
@stew
Mar 20 2015 17:29
+  def map[B](f: A => B): Lazy[B] = this match {
+    case Eager(a) => Lazy(f(a))
+    case ByName(ff) => ByName(() => f(ff()))
+    case need @ ByNeed() => new ByNeed[B] {
+      override lazy val value = f(need.value)
+    }
+  }
Erik Osheim
@non
Mar 20 2015 17:29
@stew right, but should the function application be lazy or strict (when Lazy[A] is strict) ?
Mike (stew) O'Connor
@stew
Mar 20 2015 17:29
doens't that preserve the flavor of lazy?
Erik Osheim
@non
Mar 20 2015 17:32
you might want case Eager(a) => Eager(f(a))
Mike (stew) O'Connor
@stew
Mar 20 2015 17:32
oh, right
Erik Osheim
@non
Mar 20 2015 17:33
anyway, i personally didn't find it confusing (which isn't shocking since i wrote it) but after a lot of discussion i though that @tpolecat's plan was probably the best compromise (or at least, something everyone could live with).