
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 or 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" -> ... _ -> ... or checkFoo x | unpack x == "Foo" = ... | otherwise = ... - I may be wrong but they require the recomputation on each call of unpack 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" like. PS. data FooBar a = Foo | Bar deriving Show class IsString (FooBar Char) where toString _ = Foo class IsList FooBar where toList _ = Bar show ("1234" :: FooBar Char) == ???