Let strict for unboxed types

Manuel M. T. Chakravarty chak@cse.unsw.edu.au
Thu, 01 Mar 2001 16:19:29 +1100


Simon Peyton-Jones <simonpj@microsoft.com> wrote,

> That's right.  Unboxed-type things are allowed on the RHS
> of a let iff they are ok-for-speculation; that is, iff it's ok to evaluate
> them at any time.  (We want to float let-bindings freely.)
> Otherwise it's casified.  For exampe
> 	let x::Int# = fac 5#
> 	in ...
> 
> is not allowed, if fac :: Int -> Int#

But exactly this is accepted by the HEAD:

  import PrelGHC
  import PrelBase

  fac    :: Int# -> Int#
  fac 0#  = 1#
  fac n#  = fac (n# -# 1#) *# n#

  main = print $
	  let x::Int# = fac 5#
	  in I# x

works fine.  When after the `in' there is a case expression
of which only one branch refers to `x', the binding of the
unboxed value is evaluated regardless of which alternative
is taken.  That is what I meant with my question of whether
``let is strict for unboxed types''.  It is a strict binding
like in ML.

"Simon Marlow" <simonmar@microsoft.com> wrote,

> The only alternative is to disallow these forms of expression (which I
> believe GHC did at one point, right?) but I find the current behaviour
> incredibly useful.

I find it useful, too, but was just wondering whether I
should add a remark to the documentation.  And from what
SimonPJ says, GHC seems to allow more than he expected.

Cheers,
Manuel