diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..8392d15 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake \ No newline at end of file diff --git a/.gitignore b/.gitignore index 62a1808..6a8475f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ *.hi *.o .DS_Store +.claude +.direnv diff --git a/ch1/baby.hs b/ch1/baby.hs index 2e1e6d9..2195e3b 100644 --- a/ch1/baby.hs +++ b/ch1/baby.hs @@ -1,3 +1,5 @@ +module Baby where + doubleMe x = x + x doubleUs x y = doubleMe x + doubleMe y diff --git a/ch10/heathrow.hs b/ch10/heathrow.hs index 91bb392..4ca9ba2 100644 --- a/ch10/heathrow.hs +++ b/ch10/heathrow.hs @@ -1,3 +1,5 @@ +module Heathrow where + import Data.List data Section = Section { getA :: Int, getB :: Int, getC :: Int } diff --git a/ch10/solverpn.hs b/ch10/solverpn.hs index 8b6d555..a479714 100644 --- a/ch10/solverpn.hs +++ b/ch10/solverpn.hs @@ -1,3 +1,5 @@ +module SolverPN where + solveRPN :: String -> Double solveRPN = head . foldl foldingFunction [] . words where foldingFunction (x:y:ys) "*" = (y * x):ys diff --git a/ch11/cmaybe.hs b/ch11/cmaybe.hs index 7fe8e70..61d149c 100644 --- a/ch11/cmaybe.hs +++ b/ch11/cmaybe.hs @@ -1,3 +1,5 @@ +module CMaybe where + data CMaybe a = CNothing | CJust Int a deriving Show instance Functor CMaybe where diff --git a/ch11/fmapping_io.hs b/ch11/fmapping_io.hs index a6304db..c631515 100644 --- a/ch11/fmapping_io.hs +++ b/ch11/fmapping_io.hs @@ -1,3 +1,5 @@ +module FmappingIO where + import Data.Char import Data.List diff --git a/ch11/iofunctor.hs b/ch11/iofunctor.hs index 0e87a42..edc1278 100644 --- a/ch11/iofunctor.hs +++ b/ch11/iofunctor.hs @@ -1,3 +1,5 @@ +module IOFunctor where + main = do line <- fmap reverse getLine putStrLn $ "You said " ++ line ++ " backwards!" diff --git a/ch13/knight.hs b/ch13/knight.hs index 4ba2904..36a5e0e 100644 --- a/ch13/knight.hs +++ b/ch13/knight.hs @@ -1,3 +1,5 @@ +module Knight where + type KnightPos = (Int, Int) type KnightPath = [KnightPos] diff --git a/ch14/difflist.hs b/ch14/difflist.hs index c98d064..1377d83 100644 --- a/ch14/difflist.hs +++ b/ch14/difflist.hs @@ -1,3 +1,5 @@ +module DiffList where + import Control.Monad.Writer newtype DiffList a = DiffList { getDiffList :: [a] -> [a] } diff --git a/ch14/knight-monadic.hs b/ch14/knight-monadic.hs index 67ee42a..2abbcf1 100644 --- a/ch14/knight-monadic.hs +++ b/ch14/knight-monadic.hs @@ -1,3 +1,5 @@ +module KnightMonadic where + import Control.Monad type KnightPos = (Int, Int) type KnightPath = [KnightPos] diff --git a/ch14/monadic.hs b/ch14/monadic.hs index b0cd43f..f5b5650 100644 --- a/ch14/monadic.hs +++ b/ch14/monadic.hs @@ -1,3 +1,5 @@ +module Monadic where + import Control.Monad.Writer keepSmall :: Int -> Writer [String] Bool diff --git a/ch14/prob.hs b/ch14/prob.hs index f2cf393..798e4ce 100644 --- a/ch14/prob.hs +++ b/ch14/prob.hs @@ -1,3 +1,5 @@ +module Prob where + import Data.Ratio import Data.Bifunctor import Control.Monad diff --git a/ch14/random.hs b/ch14/random.hs index c4eb85c..7f5e3db 100644 --- a/ch14/random.hs +++ b/ch14/random.hs @@ -1,3 +1,5 @@ +module Random14 where + import System.Random import Control.Monad.State @@ -9,4 +11,4 @@ threeCoins = do a <- randomSt b <- randomSt c <- randomSt - return (a, b, c) \ No newline at end of file + return (a, b, c) diff --git a/ch14/reader.hs b/ch14/reader.hs index af3ea6a..2fa1261 100644 --- a/ch14/reader.hs +++ b/ch14/reader.hs @@ -1,3 +1,5 @@ +module Reader where + addStuff :: Int -> Int addStuff = do a <- (*2) diff --git a/ch14/ropewalker.hs b/ch14/ropewalker.hs index 152fedd..49064b3 100644 --- a/ch14/ropewalker.hs +++ b/ch14/ropewalker.hs @@ -1,3 +1,5 @@ +module RopeWalker where + -- In the previous chapter, we used the monadic aspects of Maybe -- to simulate birds landing on the balancing pole of a tightrope -- walker. As an exercise, you can rewrite that with the error diff --git a/ch14/stack.hs b/ch14/stack.hs index 8f0c5b6..2615ceb 100644 --- a/ch14/stack.hs +++ b/ch14/stack.hs @@ -1,3 +1,5 @@ +module Stack where + import Control.Monad.State type Stack = [Int] diff --git a/ch15/filesystem.hs b/ch15/filesystem.hs index c8147d5..9c3a5dd 100644 --- a/ch15/filesystem.hs +++ b/ch15/filesystem.hs @@ -1,3 +1,5 @@ +module Filesystem where + import Data.List (break) x -: f = f x diff --git a/ch15/tree.hs b/ch15/tree.hs index 9f1f234..5c139ce 100644 --- a/ch15/tree.hs +++ b/ch15/tree.hs @@ -1,3 +1,5 @@ +module Tree15 where + data Tree a = Empty | Node a (Tree a) (Tree a) deriving Show diff --git a/ch2/factorial.hs b/ch2/factorial.hs index 4f8ad4e..c09134b 100644 --- a/ch2/factorial.hs +++ b/ch2/factorial.hs @@ -1,3 +1,5 @@ +module Factorial where + factorial :: Integer -> Integer factorial n = product [1..n] diff --git a/ch3/lucky.hs b/ch3/lucky.hs index 08a9f7f..e7b502f 100644 --- a/ch3/lucky.hs +++ b/ch3/lucky.hs @@ -1,3 +1,5 @@ +module Lucky where + lucky :: Int -> String lucky 7 = "LUCKY NUMBER SEVEN!" lucky x = "Sorry, you're out of luck, pal!" diff --git a/ch4/maximum.hs b/ch4/maximum.hs index 82f1d33..94f2903 100644 --- a/ch4/maximum.hs +++ b/ch4/maximum.hs @@ -1,3 +1,5 @@ +module Maximum where + maximum' :: (Ord a) => [a] -> a maximum' [] = error "maximum of empty list!" maximum' [x] = x diff --git a/ch7/deriving.hs b/ch7/deriving.hs index c235787..bca016b 100644 --- a/ch7/deriving.hs +++ b/ch7/deriving.hs @@ -1,3 +1,5 @@ +module Deriving where + data Person = Person { firstName :: String , lastName :: String , age :: Int} deriving (Eq, Show, Read) diff --git a/ch7/lockers.hs b/ch7/lockers.hs index d9eb103..3b4d739 100644 --- a/ch7/lockers.hs +++ b/ch7/lockers.hs @@ -1,3 +1,5 @@ +module Lockers where + import qualified Data.Map as Map data LockerState = Taken | Free deriving (Show, Eq) diff --git a/ch7/modules.hs b/ch7/modules.hs index 547efcd..c5a75b7 100644 --- a/ch7/modules.hs +++ b/ch7/modules.hs @@ -1,3 +1,5 @@ +module Modules where + import Data.List import Data.Char import qualified Data.Map as Map diff --git a/ch7/ownlist.hs b/ch7/ownlist.hs index 3775078..1df7e38 100644 --- a/ch7/ownlist.hs +++ b/ch7/ownlist.hs @@ -1,3 +1,5 @@ +module OwnList where + infixr 7 :-: data List a = Empty | a :-: (List a) deriving (Show, Read, Eq, Ord) diff --git a/ch7/typesyn.hs b/ch7/typesyn.hs index ee04db4..53eeb14 100644 --- a/ch7/typesyn.hs +++ b/ch7/typesyn.hs @@ -1,3 +1,5 @@ +module TypeSyn where + type PhoneNumber = String type Name = String type PhoneBook = [(Name, PhoneNumber)] diff --git a/ch7/yesno.hs b/ch7/yesno.hs index ec8a9ee..8682131 100644 --- a/ch7/yesno.hs +++ b/ch7/yesno.hs @@ -1,3 +1,5 @@ +module YesNo where + import Traffic import Tree diff --git a/ch8/forever.hs b/ch8/forever.hs index 60c44a4..32eedb6 100644 --- a/ch8/forever.hs +++ b/ch8/forever.hs @@ -1,3 +1,5 @@ +module Forever where + import Control.Monad import Data.Char import System.IO diff --git a/ch8/form.hs b/ch8/form.hs index 7ae898e..f707b52 100644 --- a/ch8/form.hs +++ b/ch8/form.hs @@ -1,3 +1,5 @@ +module Form where + import Control.Monad main = do diff --git a/ch8/helloworld.hs b/ch8/helloworld.hs index f91e3f6..57a063d 100644 --- a/ch8/helloworld.hs +++ b/ch8/helloworld.hs @@ -1 +1,3 @@ +module HelloWorld where + main = putStrLn "Hello, world" \ No newline at end of file diff --git a/ch8/putStr.hs b/ch8/putStr.hs index 1348676..f6b972d 100644 --- a/ch8/putStr.hs +++ b/ch8/putStr.hs @@ -1,3 +1,5 @@ +module PutStr where + main = do putStr "hey, " putStr "I'm " diff --git a/ch8/reverse.hs b/ch8/reverse.hs index f6ac08a..b9dc2d6 100644 --- a/ch8/reverse.hs +++ b/ch8/reverse.hs @@ -1,3 +1,5 @@ +module Reverse where + main = do line <- getLine if null line diff --git a/ch8/rock.hs b/ch8/rock.hs index 4d03c99..66edcec 100644 --- a/ch8/rock.hs +++ b/ch8/rock.hs @@ -1,3 +1,5 @@ +module Rock where + main = do putStrLn "Hello, what's your name?" name <- getLine diff --git a/ch8/rock2.hs b/ch8/rock2.hs index 88ebcd3..2845892 100644 --- a/ch8/rock2.hs +++ b/ch8/rock2.hs @@ -1,3 +1,5 @@ +module Rock2 where + import Data.Char main = do diff --git a/ch8/when.hs b/ch8/when.hs index 799d08f..1ab678a 100644 --- a/ch8/when.hs +++ b/ch8/when.hs @@ -1,3 +1,5 @@ +module When where + import Control.Monad main = do diff --git a/ch9/appendtodo.hs b/ch9/appendtodo.hs index 49aa196..249b209 100644 --- a/ch9/appendtodo.hs +++ b/ch9/appendtodo.hs @@ -1,3 +1,5 @@ +module AppendTodo where + import System.IO main = do diff --git a/ch9/arg-test.hs b/ch9/arg-test.hs index ae83dfa..bd67404 100644 --- a/ch9/arg-test.hs +++ b/ch9/arg-test.hs @@ -1,3 +1,5 @@ +module ArgTest where + import System.Environment import Data.List diff --git a/ch9/bytestringcopy.hs b/ch9/bytestringcopy.hs index 4401d8a..a97549f 100644 --- a/ch9/bytestringcopy.hs +++ b/ch9/bytestringcopy.hs @@ -1,3 +1,5 @@ +module ByteStringCopy where + import System.Environment import System.Directory import System.IO diff --git a/ch9/capslocker.hs b/ch9/capslocker.hs index 1efd973..a8a03dd 100644 --- a/ch9/capslocker.hs +++ b/ch9/capslocker.hs @@ -1,3 +1,5 @@ +module CapsLocker where + import Control.Monad import Data.Char diff --git a/ch9/deletetodo.hs b/ch9/deletetodo.hs index f41bdea..28e23a7 100644 --- a/ch9/deletetodo.hs +++ b/ch9/deletetodo.hs @@ -1,3 +1,5 @@ +module DeleteTodo where + import System.IO import System.Directory import Data.List diff --git a/ch9/girlfriend-caps.hs b/ch9/girlfriend-caps.hs index 8c81ba1..e66de0d 100644 --- a/ch9/girlfriend-caps.hs +++ b/ch9/girlfriend-caps.hs @@ -1,3 +1,5 @@ +module GirlfriendCaps where + import System.IO import Data.Char diff --git a/ch9/girlfriend.hs b/ch9/girlfriend.hs index b3dd315..58e120a 100644 --- a/ch9/girlfriend.hs +++ b/ch9/girlfriend.hs @@ -1,3 +1,5 @@ +module Girlfriend where + import System.IO main = do diff --git a/ch9/guess_the_number.hs b/ch9/guess_the_number.hs index 7d4b986..bf512c8 100644 --- a/ch9/guess_the_number.hs +++ b/ch9/guess_the_number.hs @@ -1,3 +1,5 @@ +module GuessTheNumber where + import System.Random import Control.Monad(when) diff --git a/ch9/palindrome.hs b/ch9/palindrome.hs index 641f93e..0f51edf 100644 --- a/ch9/palindrome.hs +++ b/ch9/palindrome.hs @@ -1,3 +1,5 @@ +module Palindrome where + main = interact respondPalindrome respondPalindrome :: String -> String diff --git a/ch9/random.hs b/ch9/random.hs index 77b6841..94d19b9 100644 --- a/ch9/random.hs +++ b/ch9/random.hs @@ -1,3 +1,5 @@ +module Random where + import System.Random threeCoins :: StdGen -> (Bool, Bool, Bool) diff --git a/ch9/random_string.hs b/ch9/random_string.hs index abea2d1..a7fcc62 100644 --- a/ch9/random_string.hs +++ b/ch9/random_string.hs @@ -1,3 +1,5 @@ +module RandomString where + import System.Random main = do diff --git a/ch9/shortlinesonly.hs b/ch9/shortlinesonly.hs index 8dd6dcb..943ce42 100644 --- a/ch9/shortlinesonly.hs +++ b/ch9/shortlinesonly.hs @@ -1,3 +1,5 @@ +module ShortLinesOnly where + main = do contents <- getContents putStr (shortLinesOnly contents) diff --git a/ch9/shortonly.hs b/ch9/shortonly.hs index 40e8e24..d5cc1aa 100644 --- a/ch9/shortonly.hs +++ b/ch9/shortonly.hs @@ -1,3 +1,5 @@ +module ShortOnly where + main = interact shortLinesOnly shortLinesOnly :: String -> String diff --git a/ch9/todo.hs b/ch9/todo.hs index 65855ed..1033df3 100644 --- a/ch9/todo.hs +++ b/ch9/todo.hs @@ -1,3 +1,5 @@ +module Todo where + -- todo check that index is not out of bounds -- todo check that the index is a number diff --git a/flake.nix b/flake.nix index 683962c..e4d28a4 100644 --- a/flake.nix +++ b/flake.nix @@ -11,8 +11,19 @@ let pkgs = nixpkgs.legacyPackages.${system}; - haskellPackages = pkgs.haskell.packages.ghc9122; - + haskellPackages = pkgs.haskell.packages.ghc9122.override { + overrides = self: super: { + brick = pkgs.haskell.lib.overrideCabal super.brick (oldAttrs: { + version = "2.9"; + src = pkgs.fetchFromGitHub { + owner = "jtdaugherty"; + repo = "brick"; + rev = "13fc9ede648de359366ed1d2b865fbd847fb2dc5"; + sha256 = "sha256-t+S7BkKYuq71rsiffOTuwgnmlWwGPlp5dxHZscsu9w8="; + }; + }); + }; + }; ghcWithPackages = haskellPackages.ghcWithPackages (ps: with ps; [ # Basic packages that might be useful for the examples ]); @@ -47,4 +58,4 @@ ''; }; }); -} \ No newline at end of file +}