Unpacking sum types

Joachim Breitner mail at joachim-breitner.de
Tue Sep 8 08:14:43 UTC 2015


Hi,

Am Dienstag, den 08.09.2015, 08:53 +0100 schrieb Simon Marlow:
> On 07/09/2015 15:35, Simon Peyton Jones wrote:
> > Good start.
> > 
> > I have updated the page to separate the source-language design (what the
> > programmer sees) from the implementation.
> > 
> > And I have included boxed sums as well – it would be deeply strange not
> > to do so.
> 
> How did you envisage implementing anonymous boxed sums?  What is their 
> heap representation?
> 
> One option is to use some kind of generic object with a dynamic number 
> of pointers and non-pointers, and one field for the tag. 

Why a dynamic number of pointers? All constructors of an anonymous sum
type contain precisely one pointer (just like Left and Right do), as
they are normal boxed, polymorphic data types.

Also the constructors
  (0 of 1 | _ )
  (0 of 2 | _ )
  (0 of 3 | _ )
(using Lennart’s syntax here) can all use the same info-table: At
runtime, we only care about the tag, not the arity of the sum type.

So just like for products, we could statically generate info tables for
the constructors
  (0 of ? | _ )
  (1 of ? | _ )
   ⁞
  (63 of ? | _ )
and simply do not support more than these.

(Or, if we really want to support these, start to nest them. 63² will
already go a long way... :-))

Greetings,
Joachim

-- 
Joachim “nomeata” Breitner
  mail at joachim-breitner.dehttp://www.joachim-breitner.de/
  Jabber: nomeata at joachim-breitner.de  • GPG-Key: 0xF0FBF51F
  Debian Developer: nomeata at debian.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20150908/1e5ede0f/attachment-0001.sig>


More information about the ghc-devs mailing list