Overloadable list type notation

I had an idea whose goal is to ease people into Foldable, Traversable, etc. There could be a notation that shows the generalization that is occurring. map :: Functor [_] => (a -> b) -> [a] -> [b] This means that the syntax for the list type is now syntax for the variable created by the Functor constraint. Adding such a thing to the language is probably not a good idea, but someone might possibly like such a notation for pedagogy. Of course, it will be pointed out that a Functor is not just a container. But Foldable is sometimes expressed as "anything that toList can be called on", so it should make sense there. Greg Weber

i think that thats only expressible with the style of parsing that agda mix
fix does, and for a variety of reasons I'm somewhat skeptical of the same
being viable for ghc for the forseeable future.
On Mon, Feb 16, 2015 at 11:30 PM, Greg Weber
I had an idea whose goal is to ease people into Foldable, Traversable, etc. There could be a notation that shows the generalization that is occurring.
map :: Functor [_] => (a -> b) -> [a] -> [b]
This means that the syntax for the list type is now syntax for the variable created by the Functor constraint.
Adding such a thing to the language is probably not a good idea, but someone might possibly like such a notation for pedagogy. Of course, it will be pointed out that a Functor is not just a container. But Foldable is sometimes expressed as "anything that toList can be called on", so it should make sense there.
Greg Weber
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

On Mon, 16 Feb 2015, Greg Weber wrote:
I had an idea whose goal is to ease people into Foldable, Traversable, etc. There could be a notation that shows the generalization that is occurring.
map :: Functor [_] => (a -> b) -> [a] -> [b]
This means that the syntax for the list type is now syntax for the variable created by the Functor constraint.
Btw. there is already a prefix name for the list type constructor, namely '[]'. Thus I think your example would be:
map :: Functor [] => (a -> b) -> [a] -> [b]

map :: Functor [] => (a -> b) -> [a] -> [b] already has existing, different, semantics today to what Greg is proposing here. It is asking for an instance of Functor for [] to be supplied. Since that instance exists an is scope, the constraint is trivially satisfied, so this collapses to map :: (a -> b) -> [a] -> [b] the signature we already have, with the semantics we already have. -Edward On Tue, Feb 17, 2015 at 3:38 AM, Henning Thielemann < lemming@henning-thielemann.de> wrote:
On Mon, 16 Feb 2015, Greg Weber wrote:
I had an idea whose goal is to ease people into Foldable, Traversable,
etc. There could be a notation that shows the generalization that is occurring.
map :: Functor [_] => (a -> b) -> [a] -> [b]
This means that the syntax for the list type is now syntax for the variable created by the Functor constraint.
Btw. there is already a prefix name for the list type constructor, namely '[]'. Thus I think your example would be:
map :: Functor [] => (a -> b) -> [a] -> [b]
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 On 17/02/15 05:30, Greg Weber wrote:
I had an idea whose goal is to ease people into Foldable, Traversable, etc. There could be a notation that shows the generalization that is occurring.
map :: Functor [_] => (a -> b) -> [a] -> [b]
This means that the syntax for the list type is now syntax for the variable created by the Functor constraint. I don't know how useful this is by itself.
What I *really* want is list-style syntax sugar for pattern matching. I.e. f = \xs -> case xs of [] -> foo [x] -> bar x [x:y] -> fu x y (x:xs) -> baz x xs etc. - -- Alexander alexander@plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iF4EAREIAAYFAlTjhPEACgkQRtClrXBQc7UFjQD+PU24bAdL6ju7cuK7UBN0bXyA Sxw4KZJgStb4XHVZQ6QA/iN2RXs27gyx8smAkyh55i/lRhW8+axMIiFaYFTc3/3l =EqYq -----END PGP SIGNATURE-----

On 2/17/15 10:14 AM, Alexander Berntsen wrote:
I don't know how useful this is by itself.
What I *really* want is list-style syntax sugar for pattern matching. I.e.
f = \xs -> case xs of [] -> foo [x] -> bar x [x:y] -> fu x y (x:xs) -> baz x xs
You can already use list-style syntax sugar for pattern matching. The only thing you'd have to change in your example is to replace `[x:y]` with `[x, y]`.

You can already use list-style syntax sugar for pattern matching. The only thing you'd have to change in your example is to replace `[x:y]` with `[x, y]`. Sorry, what I meant is that I would like to have this easily implementable, so that you can implement it for your own ADTs. I do not believe that this is currently possible, though I would be
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 On 17/02/15 19:21, Gabriel Gonzalez wrote: thrilled to be proven otherwise. (I have made this point so many times on IRC that my brain permitted itself way too many shortcuts with my reply to this list -- apologies!) - -- Alexander alexander@plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iF4EAREIAAYFAlTjh0YACgkQRtClrXBQc7V81AD9G7Ga20dmG1AKwBVGsMkRt1iP uTApftW93UwiXI4LFdUA/iegcpQgpeO3MvMBkQj0mRRH61C/aLasZ6NDhKrfSMGV =1KkC -----END PGP SIGNATURE-----

On Tue, Feb 17, 2015 at 1:14 PM, Alexander Berntsen
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
On 17/02/15 05:30, Greg Weber wrote:
I had an idea whose goal is to ease people into Foldable, Traversable, etc. There could be a notation that shows the generalization that is occurring.
map :: Functor [_] => (a -> b) -> [a] -> [b]
This means that the syntax for the list type is now syntax for the variable created by the Functor constraint. I don't know how useful this is by itself.
What I *really* want is list-style syntax sugar for pattern matching. I.e.
f = \xs -> case xs of [] -> foo [x] -> bar x [x:y] -> fu x y (x:xs) -> baz x xs
The existing IsList machinery gets you the [], [x], and [x,y] cases, but not (x:xs). -Edward

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 On 17/02/15 19:24, Edward Kmett wrote:
The existing IsList machinery gets you the [], [x], and [x,y] cases, but not (x:xs). Interesting... Noted! Thanks.
- -- Alexander alexander@plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iF4EAREIAAYFAlTjh5AACgkQRtClrXBQc7Wm5QEAilZPCg3kM/W2YDegRudw5WVp b1U9k3g5u68bLQfRvvwBAKPQUeekUi8MGN0ntgM4yvzU6aH5tOHr+xM/IT7YVsct =xRem -----END PGP SIGNATURE-----

View pattern support right pre-7.10 is fairly limited in that you have to write a chunk of code that can be interpreted as both a pattern and an expression, or limit yourself to just using the syntax for matching. Afterwards, this opens up a bit, and we get the new syntax for complex bidirectional pattern synonyms, as I recall, so you could make a view pattern for `:<` or something that does this, but we don't have a standard class for it. -Edward On Tue, Feb 17, 2015 at 1:44 PM, Henning Thielemann < lemming@henning-thielemann.de> wrote:
On Tue, 17 Feb 2015, Edward Kmett wrote:
The existing IsList machinery gets you the [], [x], and [x,y] cases, but
not (x:xs).
What about the view patterns?
participants (6)
-
Alexander Berntsen
-
Carter Schonwald
-
Edward Kmett
-
Gabriel Gonzalez
-
Greg Weber
-
Henning Thielemann