Foo to Bar: Naming Conventions in Haskell
kowainik.github.io
kowainik.github.io
I love the Haskell for its focus on reusable pieces, but I can’t keep up when I have to learn and remember all of those pieces to learn that ‘monoEndoSequentialAlternataverse mEmpty (.)’ is just a getter from your nifty key value store.
import qualified Data.List as DL
import qualified Data.Map.Strict as DMS
and then in code, I use DL.foldl' or DMS.foldl' as needed. Not sure if that answers your question, though. (I also use classy-prelude, it's the best IMHO.)You can also create your own functions as synonyms, if you feel like, it's easy and compiler has no issue with that. I often do that for structures (defined with "type") that I use in a module, to increase legibility.
Finally, the record dot syntax is becoming accepted to Haskell, it might help in writing IDEs that suggest methods based on types. (Peyton Jones explained somewhere that it's one of the advantages of method syntax, that it helps to show available methods.)
- modules:
- { name: [Data.List], as: List }
- { name: [Data.Map, Data.Map.Strict], as: Map }
and then you get a hlint warning if you use DL/DMS instead of List/MapThis is specifically what was trying to suggest. I wish folks would do more of it. Write the synonym for your function and then a brief docstring about what it means for this specific case.
All the generic tooling means that writing your getter or whatever might be simpler than it is in another language, but it's still worth writing. Even when it's just a synonym.
i for an index
s for state or stream
Also, in the context of lens specifically, s, t, u for the nth "containing structure" in the type signature.There's a funny story Kmett told about exploring abstractions until he wound up with a type parameterized by i m a s t a b u and deciding he should probably call it quits when the code starts threatening him.
it is really nice to know there is some logic behind names like "liftA2" and "<<$>>"
before reading this they just seemed bafflingly arbitrary