This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
instancesOfFunc> configure (lib) | |
Configuring instancesOfFunc-0.1.0.0... | |
instancesOfFunc> build (lib) | |
Preprocessing library for instancesOfFunc-0.1.0.0.. | |
Building library for instancesOfFunc-0.1.0.0.. | |
[1 of 1] Compiling InstancesOfFunc | |
/data/info/programming/haskell/haskellbook/exercises/Ch16/src/InstancesOfFunc.hs:28:31: error: | |
• Couldn't match expected type ‘a’ with actual type ‘b’ | |
‘b’ is a rigid type variable bound by |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module InstancesOfFunc where | |
import Test.QuickCheck | |
functorIdentity :: (Functor f, Eq (f a)) => f a -> Bool | |
functorIdentity f = fmap id f == f | |
functorCompose :: (Eq (f c), Functor f) => (a -> b) -> (b -> c) -> f a -> Bool | |
functorCompose f g x = (fmap g (fmap f x)) == (fmap (g . f) x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cups: | |
Installed: (none) | |
Candidate: 2.2.7-1ubuntu2 | |
Version table: | |
2.2.7-1ubuntu2 500 | |
500 http://au.archive.ubuntu.com/ubuntu bionic/main amd64 Packages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Page562Tests where | |
import Page562 | |
import Test.QuickCheck | |
import Data.List (sort) | |
--Ex 1 | |
halfIdentity :: (Fractional a, Num a) => a -> a | |
halfIdentity = (*2) . half |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Page562Tests where | |
import Page562 | |
import Test.QuickCheck | |
import Data.List (sort) | |
--Ex 1 | |
halfIdentity :: (Fractional a, Num a) => a -> a | |
halfIdentity = (*2) . half |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''Character counting as a fold''' | |
from functools import reduce | |
from itertools import repeat | |
from os.path import expanduser | |
# charCounts :: String -> Dict Char Int | |
def charCounts(s): | |
'''A dictionary of |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Page475 where | |
-- Ex 5 | |
either' :: (a -> c) -> (b -> c) -> Either a b -> c | |
either' f g eab = | |
case eab of | |
Left a -> f a | |
Right b -> g b | |
-- Ex 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Page475 where | |
f :: Either a b -> [a] -> [a] | |
f c d = case c of | |
Left x -> d ++ [x] | |
_ -> d | |
lefts' :: [Either a b] -> [a] | |
lefts' e = foldr (f) [] e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Page447 where | |
import Data.Char | |
capitalizeWord :: String -> String | |
capitalizeWord (c:cs) = toUpper c : cs | |
endsWithPeriod :: String -> Bool | |
endsWithPeriod word = last word == '.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Page442 where | |
data BinaryTree a = | |
Leaf | |
| Node (BinaryTree a) a (BinaryTree a) | |
deriving (Eq, Ord, Show) | |
preorder :: BinaryTree a -> [a] | |
preorder Leaf = [] | |
preorder (Node left val right) = [val] ++ (preorder left) ++ (preorder right) |
NewerOlder