[Haskell-cafe] One thought: Num to 0 as ? to list?

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Sun Aug 13 15:36:38 EDT 2006


On Sun, 2006-08-13 at 20:36 +0200, Marc Weber wrote:
> Is there somethinig corresponding to Num concering lists?
> 
> I mean there is + - /.. defined. + - are not type specific (Int, Double)
> neither is : [1,2] notation to Elements.. But   what  about different
> implementatins of lists? (linked lists? hash lists? array with index?
> 
> In other words: why not overload (:) ?

It might be nice to be able to use (:) to deconstruct other list like
representations however the other list representations cannot
efficiently support construction with (:). For example for the
array-with-an-index representation it is an O(n) operation.

> Then it would be possible to use "blah" for fast packed strings, too

An easier way of doing that might be to define literal strings to
desugar into a function application much like numeric literals desugar
into applications of fromIntegral.

At the moment we can at least get the performance benefit of not
converting via a list representation using GHC rules. So if you write:

pack "blah"

it gets transformed into:

packAddr "blah"#

where that literal string is just the address of a constant C string.

Duncan



More information about the Haskell-Cafe mailing list