News for hackers. Stuff that matters.
Re:Linear types make performance more predictable by x1798DE on Tuesday March 14, 2017 @07:45PM (#13872594)
Haskell I've seen often looks a lot like mathematical equations to me, where the tradition is that the notation is terse, with single letter variables (possibly with primes or other modifiers) is the norm.
Re:Linear types make performance more predictable by bloaf on Tuesday March 14, 2017 @08:04PM (#13872723)
I've thought that Haskell should consider resurrecting the old convention of putting a commented header at the beginning of their code that explains the single-letter notation in a more friendly way. Then they can have their terse syntax but make things a little friendlier for newcomers.
Re:Linear types make performance more predictable by mrkgnao on Wednesday March 15, 2017 @01:30AM (#13874025)
Javadoc-like comments ("Haddocks") are pretty widely used, and Hackage (the Haskell library index) let's you browse them and so on.

See [0] for a good example of well-commented but idiomatic Haskell (a snippet from the popular Megaparsec parser library), which includes things like:

    data ParsecT e s m a
    
    ParsecT e s m a is a parser with
    custom data component of error e, 
    stream type s, underlying monad m
    and return type a.
Admitted, that is a monad transformer, but one-character type variables with human-readable docs are both good for newcomers as well as low-friction for people who are used to the library in question.

(Strawman alert.) It is significantly more work to parse (ha) something like

    ExceptT fooException (StateT fooWorldState underlyingMonad) a
when compared to

    ExceptT e (StateT s m) a
[0]: https://hackage.haskell.org/package/megaparsec-5.2.0/docs/Te...
Re:Linear types make performance more predictable by dllthomas on Wednesday March 15, 2017 @02:01AM (#13874125)
It's also worth noting that there are conventions around type variable names. If you see an `m`, it's probably a Monad; if you see an `s`, it's probably a stream or a struct or state; `i` is likely being indexed over; the code probably doesn't care what `a` is - the surrounding code can pick it freely. If you need another, advance to the next letter (`b`, `c`, less often `n`, `o`).

Of course, Edward Kmett had a story about winding up with his code telling him `i m a s t a b u`...

Re:Linear types make performance more predictable by mrkgnao on Wednesday March 15, 2017 @08:27AM (#13875594)
f for a functor is also very common, as is k for "continuations", very generally speaking (I think this is a borrowing from Lisps?): one often sees monadic bind defined as

    m >>= k = ...
In a somewhat more esoteric vein, I love the use of w for comonads: the rationale is apparently that it looks like an upside-down m.

> Of course, Edward Kmett had a story about winding up with his code telling him `i m a s t a b u`...

Is that an indexed lens ... parameterized over a monadic type? I'd like a link to the video/article.

Re:Linear types make performance more predictable by dllthomas on Wednesday March 15, 2017 @10:53AM (#13876494)
Certainly `f` for functor. `k` is more for values than types (you usually know a continuation is some kind of (->)) but they'll often return `r`.

> I love the use of w for comonads: the rationale is apparently that it looks like an upside-down m.

That's my understanding, yeah.

> Is that an indexed lens ... parameterized over a monadic type?

Presumably further parameterized by the focus, the source structure, the target structure, the focus again, the transformed focus, and some third structure.

> I'd like a link to the video/article.

Me too :-P I see a couple references in a google search but I'm not sure where I first heard it.

Re:Linear types make performance more predictable by XorNot on Wednesday March 15, 2017 @11:09AM (#13876607)
I want to disagree a lot - the first example is way easier to parse then the second. The names tell me approximately the scope the function applies to, what I'm looking for in the code as "relevant", and which bits are doing what.

The second tells me nothing - how is this intended to be used? What scope is it intended to be used in? Why was it created? Where does it fit in the program flow?

Re:Linear types make performance more predictable by mrkgnao on Thursday March 16, 2017 @03:08AM (#13883119)
There is a certain amount of familiarity expected, sure. But anyone who has read, say, the Monads chapters in Learn You A Haskell (which is about as nonintimidating as a book can get!) should be able to guess what those types - s and so on - mean. It's akin to the mClassMember/THIS_IS_STATIC_AND_PROBABLY_FINAL conventions in Java (don't quote me on that).

In other words, my thesis is that if you aren't familiar with State, both State s and State fooAppStateType are fairly opaque.

In any case, most of the time one works with a specialized instance, for instance, one might have something likr

    newtype AppState a = 
      AppState {  
        runAppState :: 
          ReaderT Config
            (StateT AppState IO) 
            a 
      }
and then there's no problem at all.

If you're trying to understand how a library works when you're not very fluent in the language, that's what the documentation is there for! Any good library (and this is an area where's lots of room for improvement) should document the types it uses and the idioms that it lends itself to, and as one accrues experience, the whole "learning to see common patterns" takes over. The great thing about a helpful compiler of the Rust/Haskell ilk is that you make fewer mistakes in between (modulo occasionally horrific error messages).

And I'm willing to vouch for this not being expert (ha) blindness - I have only recently become comfortable enough with these things to talk about them.

Re:Linear types make performance more predictable by dpc_pw on Tuesday March 14, 2017 @07:51PM (#13872640)
Very clever way to make sure the programming language never gains any significant traction. ;)
Re:Linear types make performance more predictable by gizmo686 on Tuesday March 14, 2017 @08:56PM (#13872987)
Haskell: avoid success at all costs.
Re:Linear types make performance more predictable by bitwize on Tuesday March 14, 2017 @10:24PM (#13873293)
Obviously the solution is to encode success into the type system, such that functions which increase the chance Haskell will become a mainstream programming language fail to type-check.
Re:Linear types make performance more predictable by Magnap on Wednesday March 15, 2017 @08:23AM (#13875578)
People keep saying this as if it were meant to be parsed "(avoid success) (at all costs)", but in fact it's supposed to be "avoid (success at all costs)", in other words "principles > popularity".
Re:Linear types make performance more predictable by dllthomas on Friday March 17, 2017 @03:33PM (#13897218)
I've always understood it to be, simultaneously, jokingly the former and seriously the latter.
Re:Linear types make performance more predictable by Ixiaus on Tuesday March 14, 2017 @09:18PM (#13873065)
Only if your program doesn't type-check ;)
Re:Linear types make performance more predictable by mrkgnao on Wednesday March 15, 2017 @01:27AM (#13874015)
Re:Linear types make performance more predictable by Ixiaus on Tuesday March 14, 2017 @09:17PM (#13873057)
It certainly inherits a lot from that culture but there's a fast-growing number of industry programmers using Haskell that are bringing more approachable styles to the language; most notably: using partial functions as little as possible, using let bindings more often, using applicative-do, making variables names a bit more descriptive when it makes the waters clearer, using descriptive data type names, documenting the fields of records, documenting the arguments to a function if the types don't make it crystal clear, etc.
Re:Linear types make performance more predictable by girvo on Tuesday March 14, 2017 @11:06PM (#13873513)
Interestingly, what you've described sounds a lot like most of the OCaml I've come across (and written). I suppose that makes sense, really!
Re:Linear types make performance more predictable by fmap on Wednesday March 15, 2017 @08:32AM (#13875617)
That's a relief. All the OCaml that I've seen has been a horrible mess of single character identifiers without comments or type annotations...
Re:Linear types make performance more predictable by zzleeper on Tuesday March 14, 2017 @09:32PM (#13873117)
Is there a style guide for that? Looks incredibly useful (i.e. a Haskell pep8)
Re:Linear types make performance more predictable by mrkgnao on Wednesday March 15, 2017 @01:44AM (#13874064)
Re:Linear types make performance more predictable by ansgri on Wednesday March 15, 2017 @03:48AM (#13874482)
That is, they inherit the worst aspect of math notation.