Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions ch14/random.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Random where

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Resolve Random module name collision

This file declares module Random, but ch9/random.hs now declares the same module name. Two different source files implementing the same module cannot coexist in the same compilation unit, so attempting to load the code as a package or run both examples together will fail with duplicate module errors. Giving these modules distinct names (for example Chapter9.Random and Chapter14.Random) would avoid the conflict.

Useful? React with 👍 / 👎.


import System.Random
import Control.Monad.State

Expand Down
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 Tree where

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Rename duplicate Tree module

Declaring this file as module Tree now conflicts with ch7/Tree.hs, which was also given the module name Tree in the same commit. GHC requires every module name in a build to be unique, so attempting to compile the project (or use both modules in GHCi) will fail with a duplicate module definition error. One of the modules should be renamed or restructured to avoid the collision.

Useful? React with 👍 / 👎.


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
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
'';
};
});
}
}
Loading