Last active
August 15, 2018 03:26
-
-
Save wuct/358438133d0e1f66b23b916cea0be95f to your computer and use it in GitHub Desktop.
PureScript printf using instance chain
This file contains 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
module Main where | |
import Prelude | |
import Effect (Effect) | |
import Effect.Class.Console (log) | |
class Printf r | |
where printf :: String -> r | |
instance printfString :: Printf String | |
where printf = identity | |
else instance printfStringFunc :: Printf r => Printf (String -> r) | |
where printf a b = printf $ a <> " " <> b | |
else instance printfFunc :: (Show a, Printf r) => Printf (a -> r) | |
where printf s b = printf $ s <> " " <> show b | |
printf' :: ∀ a. Printf a => a | |
printf' = printf "" | |
main :: Effect Unit | |
main = do | |
log $ printf' 1 "a" 123 2 "b" { a: 123 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was trying to remove line:17-18 but failed, here is what I came up with: