Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Haskell #336

Merged
merged 2 commits into from
Jul 13, 2012
Merged

Haskell #336

merged 2 commits into from
Jul 13, 2012

Conversation

michelk
Copy link
Contributor

@michelk michelk commented Jul 13, 2012

Added support for haskell as foreign language (#312)

yihui added a commit that referenced this pull request Jul 13, 2012
add Haskell support; closes #312
@yihui yihui merged commit b41e925 into yihui:master Jul 13, 2012
@yihui
Copy link
Owner

yihui commented Jul 13, 2012

Awesome. Thanks!

@yihui
Copy link
Owner

yihui commented Jul 13, 2012

BTW, may I have your name added to DESCRIPTION? https://github.com/yihui/knitr/blob/master/DESCRIPTION

@michelk
Copy link
Contributor Author

michelk commented Jul 16, 2012

Off course, thanks

@yihui
Copy link
Owner

yihui commented Mar 8, 2013

hi @michelk, is it possible to write the code into a file and run ghc on the file? I mean like a shell script sh foo.sh; I tried ghc foo.hs using your example [x | x <- [1..10], odd x] but it does not work; I know little about haskell, so your help is appreciated :)

@michelk
Copy link
Contributor Author

michelk commented Mar 8, 2013

hi @yihui,
I admit, Haskell support in knitr is a bit tricky; in org-mode ob-haskell.el they write

Org-Babel support for evaluating haskell source code. This one will
be sort of tricky because haskell programs must be compiled before
they can be run, but haskell code can also be run through an
interactive interpreter.

For now lets only allow evaluation using the haskell interpreter.

Unlike R, in Haskell you couldn't just copy-paste between script and interpreter.

The following works for the interpreter:

  • single expression: ghc -e "[x | x <- [3..10], odd x]"
  • multi-line: ghc -e "let x = 5" -e "3*x"
  • using the interpreter directly: echo "[x | x <- [2..10], odd x]" | ghci

Compilation is more tricky and hard generalize; the corresponding
Haskell-program would look like

echo "main = putStrLn . unwords $ [show x | x <- [2..10], odd x]" > tmp.hs

runhaskell tmp.hs

or

ghc --make tmp.hs && ./tmp

Currently in org-mode as in knitr, you have to write code as you were in
ghci. And, as I remember, multi-line expressions in knitr are right now not
supported.

@yihui
Copy link
Owner

yihui commented Mar 8, 2013

I see. Thanks for the explanation. I'll add multiline support soon.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants