Case expressions in STG

William Knop william.knop.nospam at
Wed Jun 18 22:54:02 UTC 2014

Hi Tom,

SPJ is surely more qualified to answer than I, but I'll take a stab.

In general, it is computationally infeasible to compare functions. Granted, in your example, the function isn't being compared-- and therefore the case expr is extraneous. I don't think there exists a feasible, uncontrived example, so I imagine that's why STG forbids it (though I don't know where it's specified).


> On Jun 18, 2014, at 9:43 AM, Tom Ellis <tom-lists-ghc-devs at> wrote:
> I am reading SPJ's seminal work "Implementing lazy functional languages on
> stock hardware: the Spinless Tagless G-machine" (1992).  The paper is
> available here
> On p62 we see "The expression scrutinised by a case expression must
> eventually evaluate either to a primitive value or a constructor
> application.".
> This doesn't make sense to me.  Isn't the following a valid STG program? 
> What am I missing?  Where is it specified that the scrutinee of a case
> expression cannot be of a function type?
> {x} \n {z} -> let f = \{x} \n {y} -> g x y
>              in case f of f' -> f' z
> Thanks,
> Tom
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at

More information about the ghc-devs mailing list