Skip to content

Instantly share code, notes, and snippets.

@Heimdell
Last active July 30, 2021 17:08
Show Gist options
  • Save Heimdell/d65964f7a8ab2d44405b777e8fdf568e to your computer and use it in GitHub Desktop.
Save Heimdell/d65964f7a8ab2d44405b777e8fdf568e to your computer and use it in GitHub Desktop.
Create new haskell package _fast_
#!/usr/bin/env stack
-- stack --resolver lts-17.14 script
{-# language LambdaCase #-}
import System.Environment
import System.Directory
import System.FilePath
main = do
getArgs >>= \case
("--name" : name : "--deps" : deps) -> do
doMain name (["base", "mtl", "containers", "exceptions"] ++ deps)
["--name", name] -> do
doMain name ["base", "mtl", "containers", "exceptions"]
_ -> do
print "USAGE: roll.hs --name NAME"
doMain name deps = do
createDirectoryIfMissing True name
createDirectoryIfMissing True (name </> "src")
let content = contents name deps
writeFile (name </> ".gitignore") (unlines gitignore)
writeFile (name </> "package.yaml") content
writeFile (name </> "src" </> "It.hs") "module It where"
writeFile (name </> "stack.yaml") "resolver: lts-17.14"
putStrLn content
contents name deps = chain'
[ block "name" name
, block "dependencies" $ list deps
, block "default-extensions" $ list extensions
, block "ghc-options" "-Wall -freverse-errors"
, block "library" $ chain
[ block "source-dirs" $ list ["src"]
]
]
block :: String -> String -> String
block header content = header ++ ": " ++ content
list :: [String] -> String
list = chain . map listItem
listItem :: String -> String
listItem = ("- " ++)
chain :: [String] -> String
chain = unlines . ("" :) . map indent . lines . unlines
chain' :: [String] -> String
chain' = unlines
indent :: String -> String
indent = (" " ++)
extensions :: [String]
extensions =
[ "AllowAmbiguousTypes"
, "ApplicativeDo"
, "BlockArguments"
, "ConstraintKinds"
, "DataKinds"
, "DeriveAnyClass"
, "DeriveFoldable"
, "DeriveFunctor"
, "DeriveTraversable"
, "DerivingStrategies"
, "DerivingVia"
, "DuplicateRecordFields"
, "EmptyCase"
, "FlexibleContexts"
, "FlexibleInstances"
, "FunctionalDependencies"
, "GADTs"
, "GeneralizedNewtypeDeriving"
, "ImportQualifiedPost"
, "KindSignatures"
, "LambdaCase"
, "MultiParamTypeClasses"
, "MultiWayIf"
, "NamedFieldPuns"
, "OverloadedStrings"
, "PatternSynonyms"
, "RankNTypes"
, "ScopedTypeVariables"
, "StandaloneDeriving"
, "TemplateHaskell"
, "TypeApplications"
, "TypeFamilies"
, "TypeOperators"
, "TypeSynonymInstances"
, "UndecidableInstances"
, "ViewPatterns"
, "QuasiQuotes"
]
gitignore :: [String]
gitignore =
[ "dist"
, "dist-*"
, "cabal-dev"
, "*.o"
, "*.hi"
, "*.hie"
, "*.chi"
, "*.chs.h"
, "*.dyn_o"
, "*.dyn_hi"
, ".hpc"
, ".hsenv"
, ".cabal-sandbox/"
, "cabal.sandbox.config"
, "*.prof"
, "*.aux"
, "*.hp"
, "*.eventlog"
, ".stack-work/"
, "cabal.project.local"
, "cabal.project.local~"
, ".HTF/"
, ".ghc.environment.*"
, "*.cabal"
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment