[Haskell-cafe] naturally, length :: a -> Int

Ben Franksen ben.franksen at online.de
Tue Mar 2 12:52:56 UTC 2021


Am 01.03.21 um 17:45 schrieb Johannes Waldmann:
> let's fight Int.

I'm in.

> In a lot of code I write (for research, teaching, production),
> a lot of numbers are in fact natural numbers -
> because I am counting (e.g., number of elements in a collection)
> or pointing into what I just counted (e.g., Data.Set.elemAt).
> 
> But Haskell's "most natural" type is - Int.
> At least that's my impression from current usage in libraries
> and teaching examples (see functions length, replicate, ... ).
> 
> I've developed a horror
> of reading and writing "length something :: Int".

Same here.

> If I want to live risky (no checks) I could use Data.Word.

I think Data.Word is not so bad. Does it come with a guarantee that
maxBound=2^n-1 and all operations being treated module 2^n, for some
natural number n? That would be fine for most applications I guess.

It would be nice if one could change the semantics of under- or overflow
for Data.Word with a compiler flag, e.g. so that it throws an exception.

> That's all fine and dandy - until I call some library function...

I would support a move Int->Word in all libraries where that makes sense.

But I doubt it will happen.

Cheers
Ben



More information about the Haskell-Cafe mailing list