Strict unlifted types

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

Strict unlifted types

David Feuer
Sometimes there's an awkward expressive tension between saying that a
type is *unboxed* and saying that it is *strict* in a field. For
example, I can write

data SMaybe a = SNothing | SJust !a

or I can write

type Maybe# a = (# (# #) | a #)

but there doesn't seem to be a way to simultaneously get both unboxed
and strict. I'm wondering if it might make sense to add a type to
serve the purpose

Strict# :: Type -> TYPE 'UnliftedRep

mkStrict# :: a -> Strict# a  -- force the argument
getStrict# :: Strict# a -> a  -- do nothing, but know the result is in WHNF

Then one could write, for example,

type SMaybe# a = (# (# #) | Strict# a #)

at which point SMaybe is *precisely* isomorphic to the alternative
representation

data SMaybe' a = SMaybe' (SMaybe# a)

David
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

RE: Strict unlifted types

GHC - devs mailing list
Sounds similar to https://ghc.haskell.org/trac/ghc/wiki/UnliftedDataTypes

Simon

|  -----Original Message-----
|  From: ghc-devs [mailto:[hidden email]] On Behalf Of
|  David Feuer
|  Sent: 07 February 2018 01:11
|  To: ghc-devs <[hidden email]>
|  Subject: Strict unlifted types
|  
|  Sometimes there's an awkward expressive tension between saying that a
|  type is *unboxed* and saying that it is *strict* in a field. For
|  example, I can write
|  
|  data SMaybe a = SNothing | SJust !a
|  
|  or I can write
|  
|  type Maybe# a = (# (# #) | a #)
|  
|  but there doesn't seem to be a way to simultaneously get both unboxed
|  and strict. I'm wondering if it might make sense to add a type to
|  serve the purpose
|  
|  Strict# :: Type -> TYPE 'UnliftedRep
|  
|  mkStrict# :: a -> Strict# a  -- force the argument getStrict# ::
|  Strict# a -> a  -- do nothing, but know the result is in WHNF
|  
|  Then one could write, for example,
|  
|  type SMaybe# a = (# (# #) | Strict# a #)
|  
|  at which point SMaybe is *precisely* isomorphic to the alternative
|  representation
|  
|  data SMaybe' a = SMaybe' (SMaybe# a)
|  
|  David
|  _______________________________________________
|  ghc-devs mailing list
|  [hidden email]
|  https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.h
|  askell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-
|  devs&data=04%7C01%7Csimonpj%40microsoft.com%7Cdf3667262c11430fef8008d5
|  6dc7c3e7%7Cee3303d7fb734b0c8589bcd847f1c277%7C1%7C0%7C6365356271225789
|  33%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI
|  6Ik1haWwifQ%3D%3D%7C-
|  1&sdata=x736pxmxWrkybgV6xXLjIT9EFnKibMJuiEyJpj1SfSw%3D&reserved=0
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs