[Haskell-cafe] Re: overloaded list literals?

Maciej Piechotka uzytkownik2 at gmail.com
Mon Sep 6 14:52:49 EDT 2010

On Mon, 2010-09-06 at 10:23 +0000, Johannes Waldmann wrote:
> We have overloaded numerical literals (Num.fromInteger)
> and we can overload string literals (IsString.fromString),
> so how about using list syntax ( [], : )
> for anything list-like (e.g., Data.Sequence)?
> Of course some "minor details" would need to be worked out,
> like what methods should go in the hypothetical "class IsList"
> (is is Foldable?) and what to do about pattern matching
> (perhaps we don't need it?)

Foldable is not necessary a good choice.

Neither ByteString nor Text is Foldable. It would make hard to write
methods like:

checkMagicKey :: ByteString -> Bool
checkMagicKey (0x85:0x86:_) = True
checkMagicKey _ = False


checkFoo :: Text -> Bool
checkFoo "Foo" = True
checkFoo _ = False

> IIRC there was a time when list comprehension 
> would actually mean monad comprehension 
> (when there was no "do" notation)
> but that's not what I'm getting at here. Or is it?
> Do we have a "Haskell museum" of ideas from the past?
> Best - J.W. 

I guess the laziness and view patterns are sufficient:

checkMagicKey :: ByteString -> Bool
checkMagicKey (unpack -> 0x85:0x86:_) = True
checkMagicKey _ = False

checkFoo :: Text -> Bool
checkFoo (unpack -> "Foo") = True
checkFoo _ = False

The problems:
 - In teaching list are useful because they are simple. View patterns
are not. Even if view patterns were standard it could be considered too
complicated to teach.
 - They introduce nothing more then is already achievable as it is
possible to write
    checkFoo x = case unpack x of
                     "Foo" -> ...
                     _ -> ...  
    checkFoo x
        | unpack x == "Foo" = ...
        | otherwise = ...
 - I may be wrong but they require the recomputation on each call of

I guess that maybe active patterns should be considered to be imported
from F#. I'm not quite sure about syntax and maybe they are too "logic"


data FooBar a = Foo
              | Bar
              deriving Show

class IsString (FooBar Char) where
    toString _ = Foo

class IsList FooBar where
    toList _ = Bar

show ("1234" :: FooBar Char) == ???

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20100906/60d23a0a/attachment.bin

More information about the Haskell-Cafe mailing list