Created
March 13, 2019 23:23
-
-
Save Lysxia/9646a3a009cab563def73dd46e88c939 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| withFunction :: (Int -> IO b) -> IO b | |
| withFunction fun = do | |
| let val = 3 | |
| fun val | |
| class WithFunction proxy where | |
| withFunction_ :: proxy -> (Int -> IO b) -> IO b | |
| data Number1 = Number1 | |
| instance WithFunction Number1 where | |
| withFunction_ _ = withFunction | |
| main :: IO () | |
| main = do | |
| testFunction Number1 | |
| testFunction :: WithFunction proxy => proxy -> IO () | |
| testFunction p = do | |
| val1 <- withFunction_ p $ \val -> do putStrLn "lambda1"; return "hello" | |
| putStrLn $ "val1 = " ++ (show val1) | |
| val2 <- withFunction_ p $ \val -> do putStrLn "lambda2"; return $ val + 5 | |
| putStrLn $ "val2 = " ++ (show val2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment