Skip to content

Instantly share code, notes, and snippets.

@Lysxia
Created March 13, 2019 23:23
Show Gist options
  • Select an option

  • Save Lysxia/9646a3a009cab563def73dd46e88c939 to your computer and use it in GitHub Desktop.

Select an option

Save Lysxia/9646a3a009cab563def73dd46e88c939 to your computer and use it in GitHub Desktop.
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