Skip to content

Create a standalone Haskell version of Hscript #1

@mchav

Description

@mchav

I think this utility is pretty useful since it means you can run GHCi scripts quickly.

The core functionality should be:

  • Wrap all code blocks (blocks separated by empty lines) in :{...:}
  • Separate declaration from usage
  • Top level I/O actions, groups of imports, and template Haskell should be in their own blocks.
  • Group ghci directives together.
  • It should contain some default extensions (overloaded strings, type applications, maybe template Haskell etc).

1) Separate declaration from usage

x = 5
print x

Should be:

:{
x = 5
:}
:{
print x
:}

2) Separate I/O action

x <- pure 5
print x

Should be:

:{
x <- pure 5
:}
:{
print x
:}

3) Group signature and bindings

f :: Int -> Int
f x = x + 1

print (f 5)

Should be:

:{
f :: Int -> Int
f x = x + 1
:}
:{
print (f 5)
:}

3) Separate imports

import Data.List
ys = sort [5,4,3,2,1]
print (f 5)

Should be:

:{
import Data.List
:}
:{
ys = sort [5,4,3,2,1]
:}
:{
print ys
:}

4) Template Haskell splices should converted to GHCi template haskell format.

$(F.declareColumns df)

print (df |> D.filterWhere (x .> 5))

Should be:

-- include template haskell extension since we know it's in the script.
:{
:set -XTemplateHaskell
:}
:{
_ = (); F.declareColumns df 
:}
:{
print (df |> D.filterWhere (x .> 5))
:}

5) Group GHCI directives (or have them in their own blocks if t.

:set -XScopedTYpeVariables

:set -XOverloadedLabels
print 4

Should be:

:{
:set -XScopedTYpeVariables
:}
:{
:set -XOverloadedLabels 
:}
:{
print 4
:}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions