Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tonymorris committed Nov 6, 2012
2 parents 0cce33c + 2d772e7 commit 25ee51a
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 14 deletions.
5 changes: 1 addition & 4 deletions .ghci
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
:m + Test.QuickCheck
:set prompt ">> "
:set -Wall
:set -fno-warn-unused-imports
:def hlint const . return $ ":! hlint \"src\""
:def hoogle \s -> return $ ":! hoogle --count=15 \"" ++ s ++ "\""
:def pl \s -> return $ ":! pointfree \"" ++ s ++ "\""

10 changes: 0 additions & 10 deletions Course.lkshw

This file was deleted.

103 changes: 103 additions & 0 deletions package
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env runhaskell

import Control.Monad.Instances
import Data.List
import Data.Time
import System.Directory
import System.Environment
import System.FilePath
import System.IO

main ::
IO ()
main =
do args <- getArgs
case args of
[] ->
do n <- getProgName
hPutStrLn stderr (n ++ " <package-name> [first-module]")
(h:t) ->
let piml = "package.iml"
himl = h ++ ".iml"
mods = "modules.xml"
imods = ".idea" </> mods
pcabal = "package.cabal"
hcabal = h ++ ".cabal"
ghci = ".ghci"
src = "src"
in do tmp <- getTemporaryDirectory
now <- getCurrentTime
let dir = tmp </> h </> show now
createDirectoryIfMissing True dir
cbl <- readFile pcabal
writeFile (dir </> hcabal) (replace "Name: package" ("Name: " ++ h) cbl)
copyFile piml (dir </> himl)
iml <- readFile imods
writeFile (dir </> mods) (replace piml himl iml)
removeFile piml
removeFile pcabal
-- OMG I am such a nasty hacker
case t of
[] -> return ()
(m:_) -> let n = split (=='.') m
s [] = error "unexpected empty list"
s [l] = ([], l)
s (hh:tt@(_:_)) = let (p, k) = s tt
in (hh:p, k)
in case n of
[] -> return ()
_ -> let (p, k) = s n
p' = src </> joinPath p
k' = k ++ ".hs"
in do createDirectoryIfMissing True p'
let m' = intercalate "." p ++ '.' : k
m'' = intercalate "/" p ++ '/' : k ++ ".hs"
writeFile (p' </> k') ("module " ++ m' ++ " where\n")
hc <- readFile (dir </> hcabal)
-- eek!
length hc `seq` writeFile (dir </> hcabal) (replace "Exposed-Modules:\n M" ("Exposed-Modules:\n " ++ m') hc)
removeFile (src </> "M.hs")
hghci <- readFile ghci
writeFile (dir </> ghci) (replace "M.hs" m'' hghci)
copyFile (dir </> ghci) ghci
copyFile (dir </> himl) himl
copyFile (dir </> hcabal) hcabal
copyFile (dir </> mods) imods


replace ::
Eq a =>
[a]
-> [a]
-> [a]
-> [a]
replace [] _ v =
v
replace _ _ [] =
[]
replace x y v@(c:w) =
let fd [] [] =
Just []
fd [] e@(_:_) =
Just e
fd (_:_) [] =
Nothing
fd (h:t) (h':t') =
if h == h'
then
fd t t'
else
Nothing
in case fd x v of
Nothing -> c : replace x y w
Just q -> y ++ replace x y q

split ::
(a -> Bool)
-> [a]
-> [[a]]
split p =
unfoldr (\x -> case x of
[] -> Nothing
_ -> Just . fmap (drop 1) . break p $ x)

File renamed without changes.

0 comments on commit 25ee51a

Please sign in to comment.