Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
*.hi
*.o
.DS_Store
.claude
.direnv
2 changes: 2 additions & 0 deletions ch1/baby.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Baby where

doubleMe x = x + x

doubleUs x y = doubleMe x + doubleMe y
Expand Down
2 changes: 2 additions & 0 deletions ch10/heathrow.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Heathrow where

import Data.List

data Section = Section { getA :: Int, getB :: Int, getC :: Int }
Expand Down
2 changes: 2 additions & 0 deletions ch10/solverpn.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module SolverPN where

solveRPN :: String -> Double
solveRPN = head . foldl foldingFunction [] . words
where foldingFunction (x:y:ys) "*" = (y * x):ys
Expand Down
2 changes: 2 additions & 0 deletions ch11/cmaybe.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module CMaybe where

data CMaybe a = CNothing | CJust Int a deriving Show

instance Functor CMaybe where
Expand Down
2 changes: 2 additions & 0 deletions ch11/fmapping_io.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module FmappingIO where

import Data.Char
import Data.List

Expand Down
2 changes: 2 additions & 0 deletions ch11/iofunctor.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module IOFunctor where

main = do
line <- fmap reverse getLine
putStrLn $ "You said " ++ line ++ " backwards!"
Expand Down
2 changes: 2 additions & 0 deletions ch13/knight.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Knight where

type KnightPos = (Int, Int)
type KnightPath = [KnightPos]

Expand Down
2 changes: 2 additions & 0 deletions ch14/difflist.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module DiffList where

import Control.Monad.Writer

newtype DiffList a = DiffList { getDiffList :: [a] -> [a] }
Expand Down
2 changes: 2 additions & 0 deletions ch14/knight-monadic.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module KnightMonadic where

import Control.Monad
type KnightPos = (Int, Int)
type KnightPath = [KnightPos]
Expand Down
2 changes: 2 additions & 0 deletions ch14/monadic.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Monadic where

import Control.Monad.Writer

keepSmall :: Int -> Writer [String] Bool
Expand Down
2 changes: 2 additions & 0 deletions ch14/prob.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Prob where

import Data.Ratio
import Data.Bifunctor
import Control.Monad
Expand Down
4 changes: 3 additions & 1 deletion ch14/random.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Random14 where

import System.Random
import Control.Monad.State

Expand All @@ -9,4 +11,4 @@ threeCoins = do
a <- randomSt
b <- randomSt
c <- randomSt
return (a, b, c)
return (a, b, c)
2 changes: 2 additions & 0 deletions ch14/reader.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Reader where

addStuff :: Int -> Int
addStuff = do
a <- (*2)
Expand Down
2 changes: 2 additions & 0 deletions ch14/ropewalker.hs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions ch14/stack.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Stack where

import Control.Monad.State

type Stack = [Int]
Expand Down
2 changes: 2 additions & 0 deletions ch15/filesystem.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Filesystem where

import Data.List (break)

x -: f = f x
Expand Down
2 changes: 2 additions & 0 deletions ch15/tree.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Tree15 where

data Tree a = Empty | Node a (Tree a) (Tree a)
deriving Show

Expand Down
2 changes: 2 additions & 0 deletions ch2/factorial.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Factorial where

factorial :: Integer -> Integer
factorial n = product [1..n]

Expand Down
2 changes: 2 additions & 0 deletions ch3/lucky.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Lucky where

lucky :: Int -> String
lucky 7 = "LUCKY NUMBER SEVEN!"
lucky x = "Sorry, you're out of luck, pal!"
Expand Down
2 changes: 2 additions & 0 deletions ch4/maximum.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Maximum where

maximum' :: (Ord a) => [a] -> a
maximum' [] = error "maximum of empty list!"
maximum' [x] = x
Expand Down
2 changes: 2 additions & 0 deletions ch7/deriving.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Deriving where

data Person = Person { firstName :: String
, lastName :: String
, age :: Int} deriving (Eq, Show, Read)
Expand Down
2 changes: 2 additions & 0 deletions ch7/lockers.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Lockers where

import qualified Data.Map as Map

data LockerState = Taken | Free deriving (Show, Eq)
Expand Down
2 changes: 2 additions & 0 deletions ch7/modules.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Modules where

import Data.List
import Data.Char
import qualified Data.Map as Map
Expand Down
2 changes: 2 additions & 0 deletions ch7/ownlist.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module OwnList where

infixr 7 :-:
data List a = Empty | a :-: (List a) deriving (Show, Read, Eq, Ord)

Expand Down
2 changes: 2 additions & 0 deletions ch7/typesyn.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module TypeSyn where

type PhoneNumber = String
type Name = String
type PhoneBook = [(Name, PhoneNumber)]
Expand Down
2 changes: 2 additions & 0 deletions ch7/yesno.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module YesNo where

import Traffic
import Tree

Expand Down
2 changes: 2 additions & 0 deletions ch8/forever.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Forever where

import Control.Monad
import Data.Char
import System.IO
Expand Down
2 changes: 2 additions & 0 deletions ch8/form.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Form where

import Control.Monad

main = do
Expand Down
2 changes: 2 additions & 0 deletions ch8/helloworld.hs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module HelloWorld where

main = putStrLn "Hello, world"
2 changes: 2 additions & 0 deletions ch8/putStr.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module PutStr where

main = do
putStr "hey, "
putStr "I'm "
Expand Down
2 changes: 2 additions & 0 deletions ch8/reverse.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Reverse where

main = do
line <- getLine
if null line
Expand Down
2 changes: 2 additions & 0 deletions ch8/rock.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Rock where

main = do
putStrLn "Hello, what's your name?"
name <- getLine
Expand Down
2 changes: 2 additions & 0 deletions ch8/rock2.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Rock2 where

import Data.Char

main = do
Expand Down
2 changes: 2 additions & 0 deletions ch8/when.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module When where

import Control.Monad

main = do
Expand Down
2 changes: 2 additions & 0 deletions ch9/appendtodo.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module AppendTodo where

import System.IO

main = do
Expand Down
2 changes: 2 additions & 0 deletions ch9/arg-test.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module ArgTest where

import System.Environment
import Data.List

Expand Down
2 changes: 2 additions & 0 deletions ch9/bytestringcopy.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module ByteStringCopy where

import System.Environment
import System.Directory
import System.IO
Expand Down
2 changes: 2 additions & 0 deletions ch9/capslocker.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module CapsLocker where

import Control.Monad
import Data.Char

Expand Down
2 changes: 2 additions & 0 deletions ch9/deletetodo.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module DeleteTodo where

import System.IO
import System.Directory
import Data.List
Expand Down
2 changes: 2 additions & 0 deletions ch9/girlfriend-caps.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module GirlfriendCaps where

import System.IO
import Data.Char

Expand Down
2 changes: 2 additions & 0 deletions ch9/girlfriend.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Girlfriend where

import System.IO

main = do
Expand Down
2 changes: 2 additions & 0 deletions ch9/guess_the_number.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module GuessTheNumber where

import System.Random
import Control.Monad(when)

Expand Down
2 changes: 2 additions & 0 deletions ch9/palindrome.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Palindrome where

main = interact respondPalindrome

respondPalindrome :: String -> String
Expand Down
2 changes: 2 additions & 0 deletions ch9/random.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Random where

import System.Random

threeCoins :: StdGen -> (Bool, Bool, Bool)
Expand Down
2 changes: 2 additions & 0 deletions ch9/random_string.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module RandomString where

import System.Random

main = do
Expand Down
2 changes: 2 additions & 0 deletions ch9/shortlinesonly.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module ShortLinesOnly where

main = do
contents <- getContents
putStr (shortLinesOnly contents)
Expand Down
2 changes: 2 additions & 0 deletions ch9/shortonly.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module ShortOnly where

main = interact shortLinesOnly

shortLinesOnly :: String -> String
Expand Down
2 changes: 2 additions & 0 deletions ch9/todo.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Todo where

-- todo check that index is not out of bounds
-- todo check that the index is a number

Expand Down
17 changes: 14 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
]);
Expand Down Expand Up @@ -47,4 +58,4 @@
'';
};
});
}
}
Loading