haskell / haskell/haskell-mode

Cabal repl without a cabal file

Open
#1,801 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Emacs Lisp
Stars
1.4k
Forks
354
Avg merge
5d 10h
Merged PRs (30d)
2

Description

Is it possible to load a Haskell file with embedded cabal build-depends, so that no extra cabal file is needed.

I have tried `(haskell-process-type 'cabal-new-repl)` and `(haskell-process-type 'cabal-repl)`, both would ask me to add containers to `haskell.cabal` file which I am trying to avoid creating.

An example, `cabal repl Store.hs` would just work, but I cannot get it work in haskell-mode:

```
{- cabal:
build-depends: base, containers
-}

module Store (save1, load1, size1, save2, load2, size2) where

import Control.Concurrent.MVar
import Data.IORef
import qualified Data.Map as M
import System.IO.Unsafe

_m1 :: IORef (M.Map String String)
{-# NOINLINE _m1 #-}
_m1 = unsafePerformIO $ newIORef M.empty
save1 k v = modifyIORef _m1 $ M.insert k v
load1 k = M.findWithDefault "" k <$> readIORef _m1
size1 = M.size <$> readIORef _m1

_m2 :: MVar (M.Map String String)
{-# NOINLINE _m2 #-}
_m2 = unsafePerformIO $ newMVar M.empty
save2 k v = modifyMVar_ _m2 $ pure . M.insert k v
load2 k = M.findWithDefault "" k <$> readMVar _m2
size2 = M.size <$> readMVar _m2

test = do
save1 "a" "42"
save1 "b" "32"
print =<< size1
print =<< load1 "a"
print =<< load1 "b"
print =<< load1 "c"

save2 "a" "42"
save2 "b" "32"
print =<< size2
print =<< load2 "a"
print =<< load2 "b"
print =<< load2 "c"
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.