commercialhaskell / rio

A standard library for Haskell
Other
838 stars 54 forks source link

What is the recommended way of list indexing? #202

Closed jeiea closed 4 years ago

jeiea commented 4 years ago

I searched something like (!!) :: [a] -> Int -> Maybe a but couldn't find one. So I leave this question.

snoyberg commented 4 years ago

The RIO.List module provides a few different list indexing functions which are total. RIO.List.Partial provides the partial (and not recommended) !! operator.

jeiea commented 4 years ago

Could not (!!) be total for compatibility? Then I have to define one myself or use partial (!!). Thanks for quick reply.

snoyberg commented 4 years ago

!! cannot be total. What would the result of [] !! 4 be?

jeiea commented 4 years ago

Nothing? I just wanted to receive Maybe type.

snoyberg commented 4 years ago

We try to match function and operator names and signatures from base, which is where the current setup comes from.

On Sat, Nov 16, 2019, 9:16 PM jeiea notifications@github.com wrote:

Nothing? I just wanted to receive Maybe type.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/commercialhaskell/rio/issues/202?email_source=notifications&email_token=AAAMCBZGSPRMQNXDL3PLCADQUAIT5A5CNFSM4JOFL232YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEHUICY#issuecomment-554648587, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAMCB7WIIOXSKLUVVIMJM3QUAIT5ANCNFSM4JOFL23Q .