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

Cabal repl without a cabal file #1801

Open
hellwolf opened this issue Feb 26, 2023 · 0 comments
Open

Cabal repl without a cabal file #1801

hellwolf opened this issue Feb 26, 2023 · 0 comments

Comments

@hellwolf
Copy link

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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant