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

David Feuer david.feuer at gmail.com
Tue Mar 2 16:17:32 UTC 2021


I think non-wrapping Word should be a different type or two. I'm quite fond
of the ring laws myself. For many practical purposes, Word64 can stand in
for Natural. A non-wrapping variant (newtype, perhaps?) might be useful.
Another occasionally useful one is Word63, which is good for bounds-checked
operations.

On Tue, Mar 2, 2021, 7:53 AM Ben Franksen <ben.franksen at online.de> wrote:

> 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
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210302/6c611709/attachment.html>


More information about the Haskell-Cafe mailing list