<div dir="ltr">The point is to create a monomorphic variant that avoids the problems with the polymorphic `pure` and would be consistent with the other container-types. A polymorphic `singleton` would be useful, but - in the same way that `Map.fromLIst` and `Set.fromList` are (usefully!) monomorphic despite equivalent `IsList` methods, we'd still want to have a concrete `List.singleton :: a -> [a]`.<div><br>I see a lot of "Why isn't `pure` good enough here?", so I'd like to reiterate that `pure` has issues:</div><div><br></div><div>- It's not immediately+syntactically obvious what's being created. List.singleton is unambiguous to read.</div><div>- Polymorphism can cause unintended changes to behavior if GHC infers a different type than you expect. Consider `length (1,2)` confusion, `fmap (+1) (Left 1)` - while these have an obviously correct instance, it can still be confusing and yield potentially incorrect results.</div><div>- Monomorphic functions can often be very useful to inform GHC about a specific type you want to fix and allow the rest of inference to work around. Typed-holes provide <b>much</b> better information when you have concrete types rather than constrained polymorphic types.</div><div>- Finally, monomorphic functions can be used to prevent ambiguous type errors in the presence of OverloadedLists and OverloadedStrings, especially when every other method in the chain is written on Foldable or similar constraints.</div><div><br></div><div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Matt Parsons</div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 13, 2019 at 4:13 PM Herbert Valerio Riedel <<a href="mailto:hvriedel@gmail.com">hvriedel@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">>  There is a concept here: create a container containing exactly one value. As Tikhon indicates, this is a different concept from pure.<br>
<br>
Fwiw, if you actually want a possibly meaningful/lawful reification of<br>
the very specific "create any container containing exactly one item"<br>
concept then an obvious approach would be to base it on the existing<br>
(IMO under-appreciated) 'IsList' abstraction; in other words basically<br>
something like<br>
<br>
    singleton :: IsList l => Item l -> l<br>
    singleton = fromListN 1 . (:[])<br>
<br>
which could either be a method of `IsList` (with the default impl<br>
above and an obvious lawful relationship to `fromList`/`toList`) or<br>
just be a top-level binding exported from "GHC.List" and/or "GHC.Exts"<br>
(which aren't governed by the Haskell Library Report and thus have a<br>
lower barrier to entry).<br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>