diffusionkinetics / open

DiffusionKinetics open-source monorepo
MIT License
115 stars 24 forks source link

Inliterate: perform IO in eval block #123

Closed GuillaumeDesforges closed 4 years ago

GuillaumeDesforges commented 4 years ago

I would like an eval block to display the result after some IO.

I tried using

```haskell top hide
-- Required to run and display IO
instance (Show a) => AskInliterate (IO a) where
    askInliterate = answerWith (show . unsafePerformIO)

But no cell is rendered after 
someIO :: IO String
someIO = return "Hello"
someIO
GuillaumeDesforges commented 4 years ago

Well, I didn't see the small => "Hello" after the code, how can I turn it into a cell below ?

GuillaumeDesforges commented 4 years ago

Got it with

```haskell top hide
-- Required to run and display IO
instance (Show a) => AskInliterate (IO a) where
    askInliterate q cts io = do
        putStrLn "<div class=\"row\">"
        putStrLn "<div class=\"col-md-12\">"
        putStr "<pre class=\"haskell\"><code>"
        putStrLn $ q
        putStrLn "</code></pre>"
        putStrLn "</div>"
        putStrLn "</div>"
        putStrLn "<div class=\"row\">"
        putStrLn "<div class=\"col-md-12\">"
        putStrLn .show . unsafePerformIO $ io
        putStrLn "</div>"
        putStrLn "</div>"