Coercible between data A a b = A a b and (a, b)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Coercible between data A a b = A a b and (a, b)

Georgi Lyubenov
Greetings!

Is there any reason behind/what is the reason behind
```
data A a b = A a b
```
and
```
(a, b)
```

not being coercible?

And in general all n-ary constructors not being coercible to one another?

Thanks in advance!

=======
Georgi

_______________________________________________
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.
Reply | Threaded
Open this post in threaded view
|

Re: Coercible between data A a b = A a b and (a, b)

Oleg Grenrus
Two data types are `Coercible` (as in Data.Coerce) if their representation in memory is the same: they are representiationally equivalent You ask for looser structural isomorphism, consider e.g. 

    data B b = B {-# UNPACK #-} !Int b

and

    (Int, b)

The values of these types have quite different representation/memory layout.

- Oleg

On 25 Feb 2019, at 16.38, Georgi Lyubenov <[hidden email]> wrote:

Greetings!

Is there any reason behind/what is the reason behind
```
data A a b = A a b
```
and
```
(a, b)
```

not being coercible?

And in general all n-ary constructors not being coercible to one another?

Thanks in advance!

=======
Georgi
_______________________________________________
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.
Reply | Threaded
Open this post in threaded view
|

Re: Coercible between data A a b = A a b and (a, b)

Brandon Allbery
Also worth remembering here is that ghc will often unpack such things if it can determine it can do so (but only with optimization iirc), so there is no guarantee that the two will be representationally equivalent even without pragmas.

On Mon, Feb 25, 2019 at 10:17 AM Oleg Grenrus <[hidden email]> wrote:
Two data types are `Coercible` (as in Data.Coerce) if their representation in memory is the same: they are representiationally equivalent You ask for looser structural isomorphism, consider e.g. 

    data B b = B {-# UNPACK #-} !Int b

and

    (Int, b)

The values of these types have quite different representation/memory layout.

- Oleg

On 25 Feb 2019, at 16.38, Georgi Lyubenov <[hidden email]> wrote:

Greetings!

Is there any reason behind/what is the reason behind
```
data A a b = A a b
```
and
```
(a, b)
```

not being coercible?

And in general all n-ary constructors not being coercible to one another?

Thanks in advance!

=======
Georgi
_______________________________________________
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

_______________________________________________
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.
Reply | Threaded
Open this post in threaded view
|

Re: Coercible between data A a b = A a b and (a, b)

Artem Pelenitsyn
In reply to this post by Oleg Grenrus
Hello Oleg,

Is there a good, somewhat up-to-date source of reference to find out what exactly is different? Is it the STG paper from 1992 (“Implementing lazy functional languages on stock hardware”)?

--
Best wishes,
Artem Pelenitstyn

On Mon, 25 Feb 2019 at 10:17 Oleg Grenrus <[hidden email]> wrote:
Two data types are `Coercible` (as in Data.Coerce) if their representation in memory is the same: they are representiationally equivalent You ask for looser structural isomorphism, consider e.g. 

    data B b = B {-# UNPACK #-} !Int b

and

    (Int, b)

The values of these types have quite different representation/memory layout.

- Oleg

On 25 Feb 2019, at 16.38, Georgi Lyubenov <[hidden email]> wrote:

Greetings!

Is there any reason behind/what is the reason behind
```
data A a b = A a b
```
and
```
(a, b)
```

not being coercible?

And in general all n-ary constructors not being coercible to one another?

Thanks in advance!

=======
Georgi
_______________________________________________
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.

_______________________________________________
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.