Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent sharing behavior for effects in Haskell #181

Open
MajaRet opened this issue Aug 30, 2020 · 0 comments
Open

Inconsistent sharing behavior for effects in Haskell #181

MajaRet opened this issue Aug 30, 2020 · 0 comments
Labels
Haskell Related to the Haskell front end

Comments

@MajaRet
Copy link
Contributor

MajaRet commented Aug 30, 2020

Description

Haskell displays some rather inconsistent behavior regarding the sharing of impure values. For example, consider the following Haskell program:

shareFunction = let g = \_ -> trace "effect" 21 in g () + g ()

Evaluating it in GHCI gives the following result:

> shareFunction
effect
effect
42

The effect is triggered each time the shared function is evaluated.

On the other hand, consider this program, which uses const instead of an anonymous function:

shareConst = let g = const $ trace "effect" 21 in g () + g ()

When this version is evaluated, the effect is only triggered once:

> shareConst
effect
42

To add to this, if the same expression is defined within the REPL and evaluated, it behaves like its counterpart with the lambda again:

> let shareConst = let g = const $ trace "effect" 21 in g () + g ()
> shareConst
effect
effect 
42

Similar results can be observed with non-deterministic expressions in Curry (compiled with PAKCS).

Given that these inconsistencies exist, we cannot accurately model Haskell's behavior in Coq in all situations. We will have to investigate the rules and inconsistencies more closely and then decide on the semantics we want to model.

Update: In fact, expressions defined in the REPL do not appear to feature sharing for let expressions at all:

> let x = trace "effect" 1 in x + x 

is evaluated to

effect
effect
2

Lambdas still cause sharing:

> (\x -> x + x) (trace "effect" 1) 
effect
2
@MajaRet MajaRet added the Haskell Related to the Haskell front end label Aug 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Haskell Related to the Haskell front end
Projects
None yet
Development

No branches or pull requests

1 participant