Allow OverloadedLists to overload (:) in patterns and expressions
@simonpj suggested (here) that the OverloadedLists
extension should also overload the (:)
constructor, both in expressions and patterns. This requires adding new methods to the IsList
typeclass; Simon suggests:
class IsList l where
type Item l
fromList :: [Item l] -> l
toList :: l -> [Item l]
fromListN :: Int -> [Item l] -> l
fromListN _ = fromList
cons :: Item l -> l -> l
unCons :: l -> Maybe (Item l, l)
This will allow users to write code that looks like it should work with overloaded lists, such as:
f [] = 1
f [_] = 2
f (x:xs) = x
Simon notes that this will probably require a GHC proposal.
Edited by sheaf