Skip to content

GHC Server for compiling Haskell code from external sources

Notifications You must be signed in to change notification settings

Ace-Interview-Prep/runGhcBWrap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ace RunGhcBubbleWrap Library

A library that uses bubblewrap CLI to allow users to submit and run arbitrary haskell source code on a virtual file system. Currently only works with one file.

In the future we will be extending this capacity through nix, to make it easy to run a full project.

Build & Run

Easiest way is to add to a project through nix.

-- Override ghc packages
let
  overrides = self: super:
  {
	runGhcBWrap = self.callPackage ./thunks/runGhcBWrap {};
  }

Try it out, enter a repl:

cd runGhcBWrap
nix-shell test-shell.nix
nix-shell -p cabal-install
cabal repl
ghc> :l Example.hs

Example.hs Contents

main :: IO ()
main = do
  testRunGhcBWrap $ unlines
    [ "{-# LANGUAGE OverloadedStrings #-}"
    , "module Main where"
    , "import System.FilePath"
    , "import System.Directory"
    , "import Data.Text"
    , "import qualified Data.Text as T"
    , "import Data.ByteString"
    , "import qualified Data.ByteString.Char8 as BS"
    , "import Data.Map"
    , "import qualified Data.Map as Map"
    , "import Data.Vector (Vector)"
    , "import qualified Data.Vector as V"
    , "import Data.Time.Clock (getCurrentTime)"
    , "import System.Directory (listDirectory)"
    , "import System.FilePath ((</>))"
    , "import System.Process (readProcess)"
    , "import Data.Aeson (encode, object, (.=))"
    , "import System.Random (randomRIO)"
    , "import System.Environment"
    , "import Control.Exception (try, SomeException)"
    , "import Control.Monad (forM_)"
    , "import Control.Monad.State (State, evalState, put, get)"
    , ""

    , "main :: IO ()"
    , "main = do"
    -- , "  print =<< getEnv \"PATH\""

    , "  putStrLn \"holy meta mate\"   "
    , "  Prelude.appendFile \"example.txt\" \"im in a file\""
    , "  Prelude.appendFile \"example.txt\" \"im in a file\""
    , "  x <- Prelude.readFile \"example.txt\" "
    , "  putStrLn $ \"haskell readFile contents: \" <> x"
    ]

About

GHC Server for compiling Haskell code from external sources

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •