Skip to content

Multi-module haskell script files #2627

@mgsloan

Description

@mgsloan

I think we should add a --multi-module option to runghc / runhaskell. This way, standalone scripts can be multiple modules. On its own, this might seem confusing - why support that if ghc doesn't support it? The motivation is to support use-cases like School of Haskell, where we need to have multiple files in one "snippet".

The more ideal implementation would be to implement this as part of ghc - https://ghc.haskell.org/trac/ghc/ticket/2551 - however that ticket was closed due to lack of interest.

Here's how the stack implementation would look:

  1. Assume that a line that starts with module are located at a module header. This can be invalidated by strange module indentation, quasi-quotes, or multi-line strings. The answer to these corners is "don't do that".

  2. Consume pragma comments backwards, for every pragma type that is allowed atop module declarations.

  3. Create a temp dir and populate it with the modules

  4. Provide these modules to runhaskell

Could also consider supporting this with ghci, but :reload won't work right. We could add direct support for this in intero, though.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions