Home > Software design >  Multiple import lines produces error in ghci
Multiple import lines produces error in ghci

Time:12-17

This is what I've tried at the ghci REPL (stack ghci 8.10.7)

λ> :{
| import Data.List
| import Data.Ratio
| :}
error: expecting a single import declaration

Why can't I do more than one import at a time? BTW, can a complete module definition be entered this way, i.e.,

λ> :{
 | module STAL where
 | import Data.List
 | import Data.Ratio
 | import Data.Decimal
 | :}

My motivation is I'm using Emacs org-mode's babel for Haskell which only works with multiple-lined code when it's surrounded in :{ :}.

CodePudding user response:

This sort of multiple-imports are currently not supported. However, there's a closed ticket asking for the same https://gitlab.haskell.org/ghc/ghc/-/issues/20473, and a merged patch that implements what you're asking for: https://gitlab.haskell.org/ghc/ghc/-/commit/7850142c09090a2eef1e1b0281acd641e843356a

I tested with GHC 9.2.1, which responded in the same way as you reported, so apparently the patch didn't make it to that release. But I suppose the next version coming out will have support for multiple-imports like this.

  • Related