How does seq force functions?

前端 未结 2 824
离开以前
离开以前 2021-02-02 10:05

Background

This question arises from a challenge Brent Yorgey posed at OPLSS: write a function f :: (Int -> Int) -> Bool that distinguishes f

2条回答
  •  长情又很酷
    2021-02-02 10:20

    There is a more higher-level description of STG-machine in How to make a fast curry: push/enter vs eval/apply

    Figure 2 contains rule CASEANY that works for functions. In this paper "is a value" proposition means either:

    • it is a saturated constructor application
    • it is a function
    • it is a partial function application (which is still a function, semantically)

    Unboxed values, including literals are treated specially, more information can be found in Unboxed values as first class citizens

    All these are implementation details and are hidden inside compiler (GHC). Haskell's case expression doesn't force it's scrutineer, only pattern-matching and seq do.

提交回复
热议问题