These are chat archives for typelevel/cats

23rd
Dec 2017
Andrew Valencik
@valencik
Dec 23 2017 15:29
My time in Haskell is measurable in hours on one hand so please forgive the naivety. Does Haskell have something to compete with implicits? I quite love implicit classes in Scala.
Loïc Girault
@lgirault
Dec 23 2017 15:30
You natively have Type Classes in haskell
when you see a signature A => B -> C
it means the A is provided implicitely
Andrew Valencik
@valencik
Dec 23 2017 15:31
Oh interesting
Fabio Labella
@SystemFw
Dec 23 2017 15:31
well
you are talking about implicit classes
implicits can also be used to model (a kind of) typeclasses
which are indeed a native feature in Haskell
note that implicit classes per se are not needed in haskell at all
implicit classes are used to give a function foo(a: A, c: C): B a syntax similar to methods
a.foo(c)
but in Haskell, you only have functions
so foo a c is the syntax for everything
there's no distinction between methods and functions (since there are no methods at all)
in addition to that, there's a syntactic feature to call functions as infix, by simply using backticks
a `foo` c
so implicit classes solve a problem that haskell does not have
there's no equivalent of implicit conversions
and implicits as type classes are covered by type classes being a native feature (with some important differences)
(there's also a lesser known extension that introduces implicit parameters, but it's seldom used)
Andrew Valencik
@valencik
Dec 23 2017 15:37
thank you! that answers a lot for me. I find the function only syntax hard to get used to. Using methods is lets your code read from left to right as a chain of "do this, and then this and then this". it's also amazing for discoverability in a repl/IDE
Fabio Labella
@SystemFw
Dec 23 2017 15:38
the left to right thing is imho a matter of use/habit
I write both languages, it's fine in both
the discoverability thing is a good point, but it doesn't really work that well with syntax enrichment ime
Andrew Valencik
@valencik
Dec 23 2017 15:39
syntax enrichment ime?
Fabio Labella
@SystemFw
Dec 23 2017 15:39
ime == in my experience (sorry)
syntax enrichment == things that aren't defined as methods on the object, but as external functions + implicit class
on the other hand, something like hoogle (search by type) it's also great for finding things, I miss that a lot in Scala
Andrew Valencik
@valencik
Dec 23 2017 15:40
I believe the scala reply will show applicable methods from an implicit class on tab complete
searching by type sounds amazing
Fabio Labella
@SystemFw
Dec 23 2017 15:40
nice then :)
Rob Norris
@tpolecat
Dec 23 2017 15:41
scalameta should make it possible for someone to write a scoogle that understands typeclasses
i would love to work on it but i'm very overallocated
Fabio Labella
@SystemFw
Dec 23 2017 15:42
note that there are much more fundamental reasons why in my opinion having one concept (functions) is better than having both the concepts of methods and functions, but they are not related to what we are talking about here (syntax)
I also don't like that writing a function in Scala is less work than writing an implicit class, but the syntax is skewed towards OO
that means that you need to do more work to have the "default" syntax
Rob Norris
@tpolecat
Dec 23 2017 15:45
The method/function thing has to be because Scala evolved out of Java. Nobody would do that on purpose.
Andrew Valencik
@valencik
Dec 23 2017 15:45
haha. funny. In my relatively brief experience with this all I've always thought that was a lovely design
Fabio Labella
@SystemFw
Dec 23 2017 15:46

def foo(f: Foo) = ??? it's easier to write, but you then have to foo(a.bar.baz)
If you want to a.bar.baz.foo, you need to

implicit class Fooer(a: Foo) {
   def foo = ???
}

which is quite a lot more ceremony (especially if you want to have both versions around, it means you basically need to duplicate each function)

Andrew Valencik
@valencik
Dec 23 2017 15:46
good point
would a built in "pipe" (unix style pipe) operator make this more natural seeming? def foo(f: Foo) = ??? and then used: a.bar.baz.|>(foo)
...even as I write it I see that "natural" is not really the right word
Rob Norris
@tpolecat
Dec 23 2017 15:48
a.foo.bar is also annoying for partial application because the thing you usually want to apply last comes first.
Fabio Labella
@SystemFw
Dec 23 2017 15:49
you don't need a built in, you can actually use an implicit class for |> (lol)
but then you stumble into the more important problems of methods vs functions
e.g. you have a type parameter, and it gets inferred to Nothing, and so on
(and let's not start talking about lack of currying, or the fact that parameter lists are not tuples, and so on)
I mean, I don't want to sound overly negative
in actual use, you get used to all these quirks
but it's still accidental complexity, which is really evident when you teach
Fabio Labella
@SystemFw
Dec 23 2017 15:55
haskell: there's functions, they all take exactly one argument, and return exactly one result
scala: right, there's methods and functions (cue discussion about eta expansion and its various quirks), you can have one or more parameter lists, or curry, you can partially apply in a few different ways, type parameters work differently, dot or no dot, implicit classes, and so on and so forth
Andrew Valencik
@valencik
Dec 23 2017 15:58
So, in Haskell are type parameters given to functions the same as value parameters?
Rob Norris
@tpolecat
Dec 23 2017 15:58
No, they're always inferred.
Andrew Valencik
@valencik
Dec 23 2017 15:59
ahh ok
Rob Norris
@tpolecat
Dec 23 2017 15:59
And implicits (typeclass instances) don't appear in the surface syntax. They're treated as type constraints.
Andrew Valencik
@valencik
Dec 23 2017 15:59
@tpolecat do you also use Haskell on a semi regular basis?
Rob Norris
@tpolecat
Dec 23 2017 16:00
Not regularly. It's too demoralizing.
Andrew Valencik
@valencik
Dec 23 2017 16:00
Hah!
Rob Norris
@tpolecat
Dec 23 2017 16:00
I do Scala for a living and if I did Haskell on my time off I would become too bitter.
I'm bitter enough.
Andrew Valencik
@valencik
Dec 23 2017 16:01
I do Python for a living and bitterly complain about it while doing Scala in my time off
Rob Norris
@tpolecat
Dec 23 2017 16:01
:-)
Nobody really knows what you can do with Scala because it's so crazy. So that's fun.
And normal people can make significant contributions, which is also fun.
And the community is my home. I have many very close friends I met doing this.
So I stay for a variety of reasons. But Haskell is reeeallly nice.
Radu Gancea
@radusw
Dec 23 2017 16:03
@SystemFw SAM types help a lot to get rid of the boilerplate
Andrew Valencik
@valencik
Dec 23 2017 16:03
I like your take on it being fun, that's a good way to look at it.
Rob Norris
@tpolecat
Dec 23 2017 16:04
Also doing FP is fun and figuring out how to do it in Scala is also fun because it's kind of a puzzle.
Fabio Labella
@SystemFw
Dec 23 2017 16:04
@radusw how?

and figuring out how to do it in Scala is also fun

that's true

although sometimes it can also be a lot of pain :joy: (e.g. stack safety)
in any case, Scala is plenty of fun
Rob Norris
@tpolecat
Dec 23 2017 16:05
Yeah.
Radu Gancea
@radusw
Dec 23 2017 16:05
e.g. implicit val showInt: Show[Int] = _.toString
Andrew Valencik
@valencik
Dec 23 2017 16:05
The community does seem really nice. And so easy to identify with those lovely Scala World painted portraits
Fabio Labella
@SystemFw
Dec 23 2017 16:06
mm I don't think that's the same boilerplate I'm referring to
Rob Norris
@tpolecat
Dec 23 2017 16:06
Ha, yeah. At least approximately. Mine makes me look like Poseidon.
Fabio Labella
@SystemFw
Dec 23 2017 16:06
I'm also not sure I like that
I see the point in Java
but here we have first class functions
Rob Norris
@tpolecat
Dec 23 2017 16:07
It's an implementation detail.
There are so many things in Scala that only make sense if you know you're really Java.
Fabio Labella
@SystemFw
Dec 23 2017 16:07
so if I instead decide to give Show a type which isn't Function1, I'm not sure I want it to unify with any Function1 of the right shape, like your example seems to imply
Andrew Valencik
@valencik
Dec 23 2017 16:12
Speaking of Java.... What seems to be the level of interest among the FP in Scala folks regarding the other backends? I guess, namely Scala-native. Do you think the more support for ScalaJS is just a function of maturity at this point?
Fabio Labella
@SystemFw
Dec 23 2017 16:12
I honestly have no idea
I think it's a matter of demand though
when people are going to start making enough noise to have Scala Native supported, we will try to support it
Mikolaj Szabo
@privateblue
Dec 23 2017 16:19
Hi! I'm trying to use Cats in a ScalaJS project, and as I'm completely new to tha latter, I might be asking a silly question, so sorry for that, but I keep getting this linking error: Referring to non-existent class cats.kernel.Order
I'm using Cats 1.0.0-RC1
Is there anything I could do about this?
Luka Jacobowitz
@LukaJCB
Dec 23 2017 16:21
Sounds like you have some library conflicts
Some library might be pulling in an older version maybe?
Mikolaj Szabo
@privateblue
Dec 23 2017 16:23
well, I'm using Dogs too, which uses a slightly older version, but not that much: [warn] Found version conflict(s) in library dependencies; some are suspected to be binary incompatible: [warn] * org.typelevel:cats-core_2.12:1.0.0-RC1 is selected over 1.0.0-MF [warn] +- privateblue:eleven_sjs0.6_2.12:0.1-SNAPSHOT (depends on 1.0.0-MF) [warn] +- org.typelevel:dogs-core_2.12:0.6.9 (depends on 1.0.0-MF)
Rob Norris
@tpolecat
Dec 23 2017 16:31
Ah yeah need to ping @stew and get an updated dogs release.
Mikolaj Szabo
@privateblue
Dec 23 2017 16:38
if I remove the Dogs dependency, I still get the same scalajs linker error Referring to non-existent class cats.kernel.Order
is it possible cats is not compiled for scalajs?
am I using the wrong cats version?
Luka Jacobowitz
@LukaJCB
Dec 23 2017 16:40
What’s the privateblue:eleven dependency?
Mikolaj Szabo
@privateblue
Dec 23 2017 16:40
that's my project
it's not a dependency, it's the actual project
Luka Jacobowitz
@LukaJCB
Dec 23 2017 16:44
Oh I see, and you have RC1 as your dependency?
Mikolaj Szabo
@privateblue
Dec 23 2017 16:44
yes
asaadza
@asaadza
Dec 23 2017 16:45
@privateblue check you have %%% in your deps (not %%)
Mikolaj Szabo
@privateblue
Dec 23 2017 16:46
oh
man
thanks!
I'm so sorry for wasting your time guys, I was stupid
Luka Jacobowitz
@LukaJCB
Dec 23 2017 16:48
Glad you figured it out! (:
Mikolaj Szabo
@privateblue
Dec 23 2017 16:50
I just wish dogs was available for sjs too
Luka Jacobowitz
@LukaJCB
Dec 23 2017 16:51
Which collections are you missing the most? Optimally we'd like to roll them into cats (:
Mikolaj Szabo
@privateblue
Dec 23 2017 16:51
I use dogs because of Set that takes an instance of cats.Eq, instead of using equals and hashCode
that's kind of a killer feature
well, technically not Eq but Order, but you know what I mean
Fabio Labella
@SystemFw
Dec 23 2017 17:03
Heap is nice
Luka Jacobowitz
@LukaJCB
Dec 23 2017 17:06
There's also SortedSet from the STD lib
Mikolaj Szabo
@privateblue
Dec 23 2017 17:11
it's not really the ordering aspect that makes me use Set from dogs, but the fact that I have to use Object.equals() for the equality relation, which just doesn't seem right
I just wanna use typeclasses to express what it means when two things equal, and then if I use sets, I'd prefer them to respect those relations encoded in those typeclasses
Luka Jacobowitz
@LukaJCB
Dec 23 2017 17:35
Yeah I get that, although sortedSetA === sortedSetB will use the Order for the elements of the sets (:
Mikolaj Szabo
@privateblue
Dec 23 2017 18:11
yeah, but the elements of the set are using hashCode, which kinda defeats the whole purpose of using a set