News for hackers. Stuff that matters.
Re:Pitfalls in Haskell by nothrabannosir on Monday August 22, 2016 @07:05AM (#12335415)
They saved the best for last:

3.5 Naming Conventions

Some names are inconsistent. For example Functor is not called Mappable while Traversable is not named after abstract nonsense. It is best to focus on what things are instead of what they are called.

Re:Pitfalls in Haskell by rspeer on Monday August 22, 2016 @11:34AM (#12337033)
In my only significant Haskell codebase, I end up using the Monoid abstraction a lot. I don't want people who have to read the code to have to cope with the word "Monoid". Monoids are simple, but the name makes them sound like they're "like monads but worse because you haven't heard of them".

I wanted to rename "Monoid" to "Joinable" in my code ("Concatenatable" is too long). But it turns out you can't alias a type class while maintaining compatibility with libraries that use it.

Re:Pitfalls in Haskell by MustardTiger on Monday August 22, 2016 @12:26PM (#12337432)
And now you would helpfully give everyone reading your code either a huge pain if they know haskell, or a completely wrong impression of what that class actually is if they don't. Great!
Re:Pitfalls in Haskell by rspeer on Monday August 22, 2016 @12:46PM (#12337572)
People who know Haskell can cope with much more indirection than a type alias. Also, I don't know many people who really know Haskell anyway.

Do tell me more about how "concatenatable" is a "completely wrong" impression of what Monoids are for. I know you can use them to, like, multiply using abstract nonsense, but that's not why you care what a Monoid is. Monoids let you generalize `mappend` over many kinds of sequences.

Re:Pitfalls in Haskell by MustardTiger on Monday August 22, 2016 @01:16PM (#12337823)
>People who know Haskell can cope with much more indirection than a type alias.

People can cope with all kinds of bad things, regardless of whether or not they know haskell. That is not an argument in favor of bad things.

>I know you can use them to, like, multiply using abstract nonsense

What? There's nothing "abstract nonsense" about it. Integers are monoids. Things that can be appended is a subset of monoids, not a description of them.

Re:Pitfalls in Haskell by dragonwriter on Monday August 22, 2016 @01:48PM (#12338018)
> Integers are monoids.

I think that one bad habit that Haskell promotes is statements of this form, which are true in Haskell because of the way Haskell forces you to define typeclasses, but aren't really "true" of the concepts modeled by typeclasses. (Integer, +, 0) defines a monoid, as does (Integer, ×, 1).

> Things that can be appended is a subset of monoids, not a description of them.

The key operation that defines a monoid is the append operation ("mappend" in the definition of the Haskell typeclass Monoid, to avoid collision with the list-specific "append" operation), which for the monoid of integers over addition is (as the name suggests) addition.

Re:Pitfalls in Haskell by MustardTiger on Monday August 22, 2016 @04:52PM (#12339340)
What? The statement is true in reality, it is not true in haskell. Haskell does not provide a Monoid instance for Integer, you have to use Sum or Product.

>The key operation that defines a monoid is the append operation

No, it is the sole monoid operation. It is named mappend in haskell, but that does not make everything it encompasses into appending. Ask someone what operations can be done on "appendables" and you will get lots of answers like looping, sizeof, etc. Append always refers to collections in other languages, so the argument that it would help people to call something different "appendable" for those people is silly.

Re:Pitfalls in Haskell by dragonwriter on Monday August 22, 2016 @05:54PM (#12339723)
> The statement is true in reality, it is not true in haskell.

No, the specific statement is true neither in reality nor in Haskell, though statements of that form (which is what I said) are often true in Haskell (e.g., List is a Monad) though not reality.

Integers are not monoids. As I stated in GP, the combination (Integer, +, 0) defines a monoid -- as does (Integer, ×, 1); there's other monoids one could define on Integers, though those are the two most obvious and useful ones. Haskell, because its designed to make statements of the form type is a typeclass has to do one of two things to support the case where multiple useful instances of a typeclass can be defined involving a particular type -- one is the newtype wrapper approach used for Sum and Product with numeric types as monoids, with the base type participating in none of the instances; the other is to choose a primary instance that the base type participates in, and relegate the others to the newtype treatment (this is what is done with lists as monads in Haskell).

Both of these approaches are workarounds for the problem that typeclass instances aren't naturally defined by a participating type alone, but by the combination of a participating type, and one or more other values (some of which are usually functions.)

Re:Pitfalls in Haskell by MustardTiger on Tuesday August 23, 2016 @08:18PM (#12348808)
>Integers are not monoids. As I stated in GP, the combination (Integer, +, 0) defines a monoid

This is simply being pedantic. We're all well aware of the meaning of what I said, as it is how it is almost always said.

>Both of these approaches are workarounds for the problem that typeclass instances

That's not a problem, it is the point. That is what typeclasses were intended to be.

Re:Pitfalls in Haskell by rspeer on Monday August 22, 2016 @01:46PM (#12337998)
So the name `mappend` is "completely wrong" in your opinion?

It's such a Haskelly response to say that I am not allowed to use a concept for what it was designed for, unless I use it in its full generality.

Re:Pitfalls in Haskell by MustardTiger on Monday August 22, 2016 @04:47PM (#12339316)
>So the name `mappend` is "completely wrong" in your opinion?

No, it is partially wrong, as I said. Appending describes a subset of monoids, not monoids.

>It's such a Haskelly response to say that I am not allowed to use a concept for what it was designed for

What on earth are you talking about? I am not a haskell person and I said nothing even remotely resembling that.

Re:Pitfalls in Haskell by nilkn on Monday August 22, 2016 @06:27PM (#12339901)
I understand your motivation, but this is a really bad idea. If I didn't know Haskell and I saw "Joinable", I wouldn't know that that meant. "Concatenatable" seems like it might be clearer, and it is a little bit but not completely, because the concept of "concatenation" doesn't apply to all monoids. For instance, here's a (not particularly useful) monoid that has nothing to do with concatenation:

    newtype Sum a = Sum { getSum :: a }
    instance (Num a) => Monoid (Sum a) where
      mempty  = Sum 0
      mappend (Sum a) (Sum b) = Sum (a + b)
Finally, and perhaps most importantly, I seriously doubt anybody reading your codebase is going to do so in complete isolation of the rest of the Haskell ecosystem. They are going to encounter the word "monoid", so you're not really doing them any favors by hiding it from them. You're just forcing them to jump through the mental hurdles of reconciling your wording with what's used everywhere else.
Re:Pitfalls in Haskell by Iceland_jack on Tuesday August 23, 2016 @12:12AM (#12341341)
It's funny you pick that example since of natural numbers can be viewed as lists (jargon: they are both free monoids) with addition as concatenation:

    type Natural = [()]

    zero, one, two, three, four :: Natural
    zero  = []
    one   = [()]
    two   = [(), ()]
    three = [(), (), ()]
    four  = [(), (), (), ()]
    ...
concatenation `(++) :: Natural -> Natural -> Natural`:

    >>> four
    [(), (), (), ()]
    >>> three ++ one
    [(), (), (), ()]
Your point still holds.

Our (non-jargon) vocabulary simply isn't equipped to deal with this level of abstraction so we need jargon if we intend to be fully descriptive — existing words don't cut it and we are just at the bottom rung of the abstraction ladder.

It's up to us as a community how much we care about faithfully describing things, Simon Peyton Jones himself claims tongue-in-cheek that their biggest mistake was not calling monads “warm fuzzy things”[0] :)

[0] http://research.microsoft.com/en-us/um/people/simonpj/papers...

Re:Pitfalls in Haskell by involans on Monday August 22, 2016 @12:07PM (#12337271)
Ironically, [join](http://hackage.haskell.org/package/base-4.9.0.0/docs/Control...) is a function on `Monad`, not `Monoid` - so `Joinable` wouldn't have been a great choice.
Re:Pitfalls in Haskell by tome on Monday August 22, 2016 @01:45PM (#12337992)
Sure you can:

    {-# LANGUAGE ConstraintKinds #-}
    
    import Data.Monoid
    
    type Joinable = Monoid
    
    something :: Joinable m => m -> m -> m
    something = (<>)
But like MustardTiger says, don't.
Re:Pitfalls in Haskell by posterboy on Monday August 22, 2016 @07:55AM (#12335627)
> abstract nonsense

this would get downvoted quickly if it was a comment

Re:Pitfalls in Haskell by Y_Y on Monday August 22, 2016 @08:25AM (#12335782)
Re:Pitfalls in Haskell by mcguire on Monday August 22, 2016 @11:00AM (#12336767)
It's a technical term.
Re:Pitfalls in Haskell by tempodox on Monday August 22, 2016 @09:30AM (#12336160)
Then let's thank the holy quantum noise that it isn't. The holier-than-thou PL fanatics here are really insufferable.
Re:Pitfalls in Haskell by wyager on Monday August 22, 2016 @11:55AM (#12337195)
The term sees wide (humorous) use in the Haskell community.
Re:Pitfalls in Haskell by wz1000 on Monday August 22, 2016 @07:40AM (#12335552)
I don't really agree with the example that was chosen. "Functor" is a well defined term with a specific meaning.

A much better example would be "Show"(Showable) vs "Traversable".

Re:Pitfalls in Haskell by tempodox on Monday August 22, 2016 @09:26AM (#12336134)
Nope. In OCaml, “Functor” is a well-defined term with a completely different meaning. Or go look what “Functor” means in Prolog. Well defined, completely different.

If you really want to mess things up, use names that mean something different every day.

But I would know what a “Mappable” should be, regardless of PL.

Re:Pitfalls in Haskell by MustardTiger on Monday August 22, 2016 @12:29PM (#12337453)
>In OCaml, “Functor” is a well-defined term with a completely different meaning

No, it has the same meaning. It does not behave identically because the languages do not have identical designs.

>But I would know what a “Mappable” should be, regardless of PL.

Lots of people wouldn't, and would be wondering what cartography has to do with anything. And even for people familiar with the functional "map", now they would just have an incorrect idea of what Functor is. Lots of Functors are things most people would not think of as being "Mappable".

Re:Pitfalls in Haskell by more_original on Tuesday August 23, 2016 @03:51AM (#12342059)
> >In OCaml, “Functor” is a well-defined term with a completely different meaning

> No, it has the same meaning. It does not behave identically because the languages do not have identical designs.

Functors in Haskell and OCaml are different things. Haskell Functors correspond to the category-theoretic notion of a functor (a thing mapping objects to objects and morphisms to morphisms in a reasonable manner). In OCaml and ML, Functors represent parameterized modules. These are not known to correspond to category-theoretic functors in any reasonable way (and there have been proposals for category-theoretic models of the ML module system). I guess the term Functor is a bit of a misnomer in the ML-like languages.

Re:Pitfalls in Haskell by MustardTiger on Tuesday August 23, 2016 @08:22PM (#12348824)
>In OCaml and ML, Functors represent parameterized modules

No, functors represent functions from a module to a module. Oh hey, that sounds just like the standard definition of a functor. As I said, the behavior is different because the languages are different, but both are named after the category theory functor, because they both emulate it.

Re:Pitfalls in Haskell by more_original on Wednesday August 24, 2016 @04:20AM (#12350542)
Please read up on the ML module system and its origins.

http://cs.stackexchange.com/questions/9769/what-is-the-relat...

Functors play very different roles in Haskell and OCaml/ML.

In Haskell, the Functor class is there to implement the functoriality of a type. If F is a functor, then one implements maps of type F A -> F B from given A -> B in a functorial way.

In ML, the term functor was chosen because they are not first-class functions, but "a level up" (much like a functor is a level up from the maps in the category that it operates on). However, if F is an ML functor, then there are no "maps" between the modules F(A) and F(B). The morphism part, which is the essence of a Functor in Haskell, is missing in ML. This is why I think that the functor terminology isn't very good in ML.

Not everything that maps one thing to another is a functor.

Re:Pitfalls in Haskell by MustardTiger on Wednesday August 24, 2016 @08:39AM (#12351548)
>However, if F is an ML functor, then there are no "maps" between the modules F(A) and F(B).

Yes there is, the functor. Just repeating a false statement won't make it come true.

Re:Pitfalls in Haskell by more_original on Wednesday August 24, 2016 @08:42AM (#12351560)
> Yes there is, the functor.

What we have is a functor F, which would be defined as in:

  module F =
    functor (X: S) -> ....
If you have two modules A and B of signature S, then you can form F(A) and F(B) and these are both modules. Now where are the maps from F(A) to F(B)? Just saying "the functor" does not explain this.

> Just repeating a false statement won't make it come true.

Exactly!

Re:Pitfalls in Haskell by MustardTiger on Wednesday August 24, 2016 @12:40PM (#12353291)
I can't teach you ocaml on hn. If you want to learn, try this: https://realworldocaml.org/
Re:Pitfalls in Haskell by more_original on Wednesday August 24, 2016 @12:58PM (#12353419)
Ok, so you can't (or don't want to) actually back up your claim that OCaml functors have the same meaning as functors in Haskell. Which is to be expected, because it's bogus. I know OCaml fairly well. The reason you can't show me the map from F(A) to F(B) is that it's not there.

If you want to claim a relation between OCaml functors and category-theoretic functors, then you must be able to justify your claims. Saying "functors represent functions from a module to a module. Oh hey, that sounds just like the standard definition of a functor." is just not a convincing argument.

Re:Pitfalls in Haskell by MustardTiger on Wednesday August 24, 2016 @05:04PM (#12355248)
>The reason you can't show me the map from F(A) to F(B) is that it's not there.

That is literally the functor. Seriously, read the chapter on modules.

Re:Pitfalls in Haskell by more_original on Wednesday August 24, 2016 @05:35PM (#12355425)
> That is literally the functor.

That would be an answer for Haskell (though a proper one would refer to fmap), but it does not work like that in OCaml. You do know some OCaml, right?

But if it's so obvious, then you can say how it works for the following concrete example:

  module type S = sig
    type t
    val f: t -> int
  end
  
  module F = functor (X: S) -> struct
    type s = X.t * X.t
    let g x = X.f x + X.f x
  end
  
  module A : S = struct
    type t = float
    let f x = int_of_float x
  end
  
  module B : S = struct
    type t = int
    let f x = 2*x
  end
  
  module X = F(A)
  module Y = F(B)
How do I get from X to Y by "literally the functor"?

The point is: In the ML module system there is no equivalent to fmap: (A -> B) -> (F A -> F B), i.e. the functor action on morphisms. So, functors in Haskell and OCaml are different things. If you want to claim otherwise, you'll have to make an actual argument for it.

Re:Pitfalls in Haskell by tome on Wednesday August 24, 2016 @06:30PM (#12355751)
> How do I get from X to Y by "literally the functor"?

NB You only need to get from X to Y in ways that arise from getting from A to B. Since there doesn't seem to be any relevant concept of morphism it's hard to see how ML functors are anything other than trivially category theoretical.

Re:Pitfalls in Haskell by more_original on Wednesday August 24, 2016 @06:35PM (#12355778)
Yes, I know! That's the point I'm trying to make. This whole discussion is about MustardTiger's claim that functors in OCaml have the same meaning as Functor in Haskell. While the latter model functors in the category-theoretic sense, the same cannot be said for the former.
Re:Pitfalls in Haskell by tome on Thursday August 25, 2016 @03:25AM (#12357390)
I know you know :) I'm just reinforcing your point.
Re:Pitfalls in Haskell by MustardTiger on Thursday August 25, 2016 @10:08AM (#12359092)
Seriously, read the book instead of repeating nonsense: https://realworldocaml.org/v1/en/html/functors.html
Re:Pitfalls in Haskell by wz1000 on Monday August 22, 2016 @10:53AM (#12336710)
Re:Pitfalls in Haskell by awj on Monday August 22, 2016 @11:47AM (#12337145)
...you're kind of helping the "don't use Functor" argument here. Most programmers are programmers first and mathematicians second, if at all. Reusing terms from math that have been overloaded in programming domains is definitely going to create a scenario where many (most?) users don't correctly understand the terms you're using.
Re:Pitfalls in Haskell by wz1000 on Wednesday August 24, 2016 @02:01AM (#12350010)
A Functor is a fundamental category-theoretical term with a specific definition that simply isn't captured by something vague like "Mappable". Precision is important when talking about such terms. It is not at all clear that (-> a) is "Mappable".

Lots of terms like Profunctor, Contravariant Functor, Bifunctor etc. (which are also the names of typecasses in Haskell) rely on the precise, category-theoretical definition of Functor.

Re:Pitfalls in Haskell by pklausler on Monday August 22, 2016 @11:37AM (#12337063)
Typeclass names could be made redundant in Haskell. If one could state a constraint in terms of a typeclass member, things would be more simple.

E.g., "classOf fmap" as a synonym for Functor.

Re:Pitfalls in Haskell by taylorfausak on Monday August 22, 2016 @12:15PM (#12337341)
I tried this out in PureScript [1]. I also made each type class have only one member and didn't specify any class hierarchy. I like how it works, but I don't know if anyone else does. It allows you to recreate the category theory type classes [2] if you want to:

    class (HasMap f) <= Functor f
    class (Functor f, HasApply f) <= Apply f
    class (Apply f, HasPure f) <= Applicative f
    class (Apply m, HasChain m) <= Bind m
    class (Applicative m, Bind m) <= Monad m
[1]: https://github.com/tfausak/purescript-neon/blob/v0.5.4/src/N... [2]: https://pursuit.purescript.org/packages/purescript-prelude/1...
Re:Pitfalls in Haskell by posterboy on Monday August 22, 2016 @07:54AM (#12335622)
only two problems in computer science and naming things is one of them
Re:Pitfalls in Haskell by zeendo on Monday August 22, 2016 @09:02AM (#12335997)
There are plenty of problems, but only two hard problems.

Actually, I think there are three hard problems in CS. The third being pedants.

Re:Pitfalls in Haskell by chriswarbo on Monday August 22, 2016 @10:07AM (#12336404)
The two hard problems are cache invalidation and naming things. The third is off-by-one errors.
Re:Pitfalls in Haskell by 0xmohit on Monday August 22, 2016 @01:40PM (#12337965)
Perhaps one more: guaranteed once-only delivery.
Re:Pitfalls in Haskell by tome on Monday August 22, 2016 @01:51PM (#12338049)
Perhaps one more: guaranteed once-only delivery.