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

Support piecewise function definition #7

Open
Ailrun opened this issue May 19, 2020 · 2 comments
Open

Support piecewise function definition #7

Ailrun opened this issue May 19, 2020 · 2 comments

Comments

@Ailrun
Copy link

Ailrun commented May 19, 2020

Current retrie picks the first piece of a piecewise function definition when trying to unfold the funciton. For example, with this code

module Test where

piece :: Bool -> Int
piece True = 1
piece False = 0

usePiece :: Bool -> Int
usePiece b = piece b

if I execute retrie -u "Test.piece" --target-file Test.hs, it returns

module Test where

piece :: Bool -> Int
piece True = 1
piece False = 0

usePiece :: Bool -> Int
usePiece b = (\ True -> 1) b

which is not semantically same.

@xich
Copy link
Contributor

xich commented May 20, 2020

So we used to have something to handle this. From the single definition, it would generate three rewrites:

  piece True = 1

  piece False = 0

  forall x. piece x = case x of
    True -> 1
    False -> 0

I removed it at some point because the function-to-case conversion was buggy and lead to some strange stuff. Things are more mature now, so I could try adding it back.

Does that seem like the behavior you would expect?

@Ailrun
Copy link
Author

Ailrun commented May 20, 2020

Yes, handling the example using case sounds reasonable for me.

facebook-github-bot pushed a commit that referenced this issue May 28, 2020
Summary: Addresses the immediate bug in #7

Reviewed By: alanz

Differential Revision: D21711726

fbshipit-source-id: 048eea9ba6cf16cac408ddecf394a177c6674028
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants