Skip to content

Instantly share code, notes, and snippets.

@dbp dbp/printf.hs
Created Oct 13, 2018

Embed
What would you like to do?
c :: String -> ((String -> a) -> a)
c str = \k -> k str
d :: (String -> a) -> Int -> a
d = \k -> (\int -> k (show (int::Int)))
s :: (String -> a) -> String -> a
s = \k -> (\str -> k (str::String))
printf :: ((String -> IO ()) -> a) -> a
printf format = format putStrLn
(%) :: ((String -> a) -> c)
-> ((String -> b) -> a)
-> (String -> b) -> c
(%) f1 f2 = \k -> f1 (\s1 -> f2 (\s2 -> k (s1 ++ s2)))
main = do printf (d % c "foo" % s) 10 "bar"
printf (d % c "foo") 10
@denismerigoux

This comment has been minimized.

Copy link

commented Jan 18, 2019

Here's what I managed to do : https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=159cfda7ced5f44149e58849955071d8.

The individual functions compile but you can't use them because currification and partial application don't really work in Rust...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.