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

Why not use rank 2 polymorphism for callCC #127

Open
SmartHypercube opened this issue Jun 13, 2022 · 2 comments
Open

Why not use rank 2 polymorphism for callCC #127

SmartHypercube opened this issue Jun 13, 2022 · 2 comments

Comments

@SmartHypercube
Copy link

I think rank 2 polymorphism is a must-have for callCC, or this code will not compile:

f :: Int -> String
f x = (`runCont` id) $ callCC $ \exit -> do
    y <- case x of
        0 -> exit "error: x == 0"
        _ -> pure x
    yString <- case y of
        1 -> exit "error: y == 1"
        _ -> pure $ show y
    pure yString

When calling functions like error, throwIO, or exit, which will never produce "normal" outputs, I generally expect the return type to be forall a. a in order to fit in any hole. But the exit produced by callCC does not work as expected. I wonder is there any specific reason?

I tried searching for related discussions, but all I could find is this article. It seems nobody is bothered by this? I have to use absurd to make it work in my code (absurd <$> exit "error: x == 0"). I'm curious about how others deal with this lack of polymorphism.

@kozross
Copy link
Collaborator

kozross commented Aug 9, 2022

I'm definitely keen on making this happen, but this requires a major version bump. Once we land 2.3.1, I'm sure @emilypi wouldn't object to this change.

@emilypi
Copy link
Member

emilypi commented Aug 10, 2022

No objections here.

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

3 participants