Proposal: Add singleton function to Data.List module
Matt
parsonsmatt at gmail.com
Tue Aug 13 23:20:20 UTC 2019
`(\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 <hvriedel at gmail.com>
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 at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20190813/b7b063f6/attachment.html>
More information about the Libraries
mailing list