org-babel for haskell not works of eval haskell block
Asked Answered
G

2

5

I am use org-mode blogging, I use org-babel to evaluate the code as following :

#+BEGIN_SRC haskell
import Data.Function (fix)

f :: Int -> Int
f = (+ 1)

main :: IO ()
main = do
      putStrLn $ show $ f 1
#+END_SRC

#+RESULTS:
: <interactive>:9:25: Not in scope: ‘f’

I found the org-babel for haskell use infer-haskell mode to start session and eval the code. I also say the session was created, and if I don't define the function but directly putStrLn "hello" , it works.

hope anyone can fix the bug :)

Genevieve answered 8/3, 2015 at 14:45 Comment(0)
T
3
#+BEGIN_SRC haskell
import Data.Function (fix)

f :: Int -> Int
let f = (+ 1)

main :: IO ()
main = do
      putStrLn $ show $ f 1
#+END_SRC

#+RESULTS:
: 2

Org's babel mode is running the Haskell code with ghci. In ghci you are required to use let to declare functions.

Thereafter answered 9/3, 2015 at 8:25 Comment(2)
I do wonder how tangle handles extracting this to a source file since let f would be invalid in a Haskell source file. For those not familiar with tangle: orgmode.org/manual/Extracting-source-code.htmlThereafter
I'm a couple years late but to clear it up for everyone who stumbles upon this: it simply doesnt, tangle doesn't work properly when combined with variables in haskellTypeset
H
6

In this article, Yoshinari Nomura describes a way to evaluate Haskell blocks using runhaskell via a Ruby script. I do not understand japanese, so I cannot translate the details, but the method has allowed me to run haskell blocks without having to write specifically for the interpreter.

Homelike answered 1/12, 2016 at 21:38 Comment(1)
This saved my day after trying around for 2 hours ... thanks.Flunk
T
3
#+BEGIN_SRC haskell
import Data.Function (fix)

f :: Int -> Int
let f = (+ 1)

main :: IO ()
main = do
      putStrLn $ show $ f 1
#+END_SRC

#+RESULTS:
: 2

Org's babel mode is running the Haskell code with ghci. In ghci you are required to use let to declare functions.

Thereafter answered 9/3, 2015 at 8:25 Comment(2)
I do wonder how tangle handles extracting this to a source file since let f would be invalid in a Haskell source file. For those not familiar with tangle: orgmode.org/manual/Extracting-source-code.htmlThereafter
I'm a couple years late but to clear it up for everyone who stumbles upon this: it simply doesnt, tangle doesn't work properly when combined with variables in haskellTypeset

© 2022 - 2024 — McMap. All rights reserved.