
Does one field name for one datatype always refer to a field with the same type? Or is there some wacky extension that would allow things like data Foo = Bar { zoom :: Int } | Baz { zoom :: Char } I'm hoping I don't have to worry about the latter possibility....

Unless something has changed very recently, the latter is illegal.
On Mon, Sep 20, 2021 at 1:14 PM David Feuer
Does one field name for one datatype always refer to a field with the same type? Or is there some wacky extension that would allow things like
data Foo = Bar { zoom :: Int } | Baz { zoom :: Char }
I'm hoping I don't have to worry about the latter possibility.... _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- brandon s allbery kf8nh allbery.b@gmail.com

On Mon, Sep 20, 2021 at 01:13:43PM -0400, David Feuer wrote:
Does one field name for one datatype always refer to a field with the same type? Or is there some wacky extension that would allow things like
data Foo = Bar { zoom :: Int } | Baz { zoom :: Char }
I'm hoping I don't have to worry about the latter possibility....
Me too! Under such circumstances what would the type of field-as-function be?

In that hypothetical context, the field name wouldn't be usable as a function—at least without future Dependent Haskell. On Mon, Sep 20, 2021, 1:19 PM Tom Ellis < tom-lists-haskell-cafe-2017@jaguarpaw.co.uk> wrote:
On Mon, Sep 20, 2021 at 01:13:43PM -0400, David Feuer wrote:
Does one field name for one datatype always refer to a field with the same type? Or is there some wacky extension that would allow things like
data Foo = Bar { zoom :: Int } | Baz { zoom :: Char }
I'm hoping I don't have to worry about the latter possibility....
Me too! Under such circumstances what would the type of field-as-function be? _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

Well, there is already an extension that turns off selector-as-function,
although I don't recall the name off the top of my head. I am not sure
there's a way to access such fields as this at all if you use it, since
e.g. HasField probably doesn't let you do types by constructor name.
On Mon, Sep 20, 2021 at 1:21 PM David Feuer
In that hypothetical context, the field name wouldn't be usable as a function—at least without future Dependent Haskell.
On Mon, Sep 20, 2021, 1:19 PM Tom Ellis < tom-lists-haskell-cafe-2017@jaguarpaw.co.uk> wrote:
On Mon, Sep 20, 2021 at 01:13:43PM -0400, David Feuer wrote:
Does one field name for one datatype always refer to a field with the same type? Or is there some wacky extension that would allow things like
data Foo = Bar { zoom :: Int } | Baz { zoom :: Char }
I'm hoping I don't have to worry about the latter possibility....
Me too! Under such circumstances what would the type of field-as-function be? _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- brandon s allbery kf8nh allbery.b@gmail.com

I was just looking for confirmation. I'm playing around with using generics
to make field-based lenses and traversals, and I don't want any unpleasant
surprises.
On Mon, Sep 20, 2021, 1:43 PM Brandon Allbery
Well, there is already an extension that turns off selector-as-function, although I don't recall the name off the top of my head. I am not sure there's a way to access such fields as this at all if you use it, since e.g. HasField probably doesn't let you do types by constructor name.
On Mon, Sep 20, 2021 at 1:21 PM David Feuer
wrote: In that hypothetical context, the field name wouldn't be usable as a function—at least without future Dependent Haskell.
On Mon, Sep 20, 2021, 1:19 PM Tom Ellis < tom-lists-haskell-cafe-2017@jaguarpaw.co.uk> wrote:
On Mon, Sep 20, 2021 at 01:13:43PM -0400, David Feuer wrote:
Does one field name for one datatype always refer to a field with the same type? Or is there some wacky extension that would allow things like
data Foo = Bar { zoom :: Int } | Baz { zoom :: Char }
I'm hoping I don't have to worry about the latter possibility....
Me too! Under such circumstances what would the type of field-as-function be? _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- brandon s allbery kf8nh allbery.b@gmail.com
participants (3)
-
Brandon Allbery
-
David Feuer
-
Tom Ellis