Discussion: lookups in maps

Jon Fairbairn jon.fairbairn at cl.cam.ac.uk
Wed Jun 10 09:30:42 UTC 2020


Andreas Abel <andreas.abel at ifi.lmu.de> writes:

> lurkup is essentially lookup returning a CPS-version (Church
> encoding) of Maybe a.
>
>   type CMaybe a = forall r. r -> (a -> r) -> r
>   lurkup' :: k -> Map k a -> CMaybe a
>
> Is it worth to add a new name for this (above the Fairbairn threshhold)?

I don’t think so :-)

> I am quite happy with writing stuff like
>
>    fromMaybe d $ Map.lookup k m

There might be a case for a flipped infix version of this. I see
that there are several in various libraries including `orElse`
and (?:) more than once.


> On 2020-06-08 21:07, David Feuer wrote:
>> lurkup :: Ord k
>>         => r -> (a -> r) -> k -> Map k a -> r
>>      lurkup r f k = maybe r f . lookup k
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

-- 
Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk




More information about the Libraries mailing list