
I want to echo everything Matt Parsons is saying. I also want to publicly thank him for participating in this discussion and for making solid arguments. Thanks, Matt! By way of explanation, I was motivated to propose this addition because a member of my team wondered aloud if there was a function to do this. I told them that I didn’t know of one, but I typically used `pure` in point-free expressions and `[x]` when the value had already been named. We searched around and couldn’t find anything: - https://www.stackage.org/lts-14.0/hoogle?q=a+-%3E+%5Ba%5D - https://hoogle.haskell.org/?hoogle=a%20-%3E%20%5Ba%5D We got to talking about other ways to express the same thing. (Everything we came up with has been seen in this thread already.) That got me wondering why there *wasn’t* a specific, monomorphic function for this. The omission seemed especially strange to my team member because they were familiar with Elm, which has this function. All that to say: This proposal is motivated by real confusion coming from a junior developer using Haskell at work. Consider how easy it is to discover and do something, rather than if it’s technically possible.
On Aug 13, 2019, at 7:20 PM, Matt
wrote: `(\x -> [x])` has the same polymorphism problem in the context of `OverloadedLists` as `pure`.
`(:[])` is also unsatisfactory. To parse it properly, you need to:
- Know that `:` is only allowed as an operator to prefix data constructors, - Know that `[]` are not legal operator characters, - Infer that you're intended to insert a space between the `:` and `[]` to get `(: [])` - Recognize it as an operator section being used prefix as a normal function
I'm neither an expert nor a lifelong Haskeller, but I have been writing it in some professional capacity for four years now, and the operator section trips me up. I can't imagine less experienced folks find it easy or intuitive. You can't even search for it on hoogle: https://hoogle.haskell.org/?hoogle=(%3A%5B%5D)
Is `(:[])` a core idiom? I never see it in work code and I've never seen it in Hackage. To check, I grepped my software directory which has all my Haskell code, and got 122 matches of (:[]) over 1,768,231 loc (as given by wc -l **/*.hs).
Matt Parsons
On Tue, Aug 13, 2019 at 4:56 PM Herbert Valerio Riedel
wrote: The point is to create a monomorphic variant [...]
But we already have at least two monomorphic variants to express this with Haskell's concise native syntax and vocabulary which has by design a preferential treatment of lists (it was considered even more important than type-sigs so that we got the `:` cons operator for lists and the `::` for type-sig annotations) -- so let's not try to fight Haskell's core idioms by hiding them behind some trivial additional redundant synonyms! I still fail to see the actual *technical* problem being solved by the original proposal asking to add yet another, wordy way to construct single-item-lists. _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries