Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.36 KB | None | 0 0
  1. \documentclass[a4]{tufte-handout}
  2. % The documentclass can be changed, but keep fonts at a reasonable size.
  3.  
  4. % comments
  5. \usepackage{comment}
  6.  
  7. % code environments
  8. \usepackage{listings}
  9. \lstnewenvironment{code}{
  10. \lstset{language=haskell, basicstyle=\ttfamily }}{}
  11. \lstnewenvironment{spec}{
  12. \lstset{language=haskell, basicstyle=\ttfamily }}{}
  13. \lstset{language=haskell, basicstyle=\ttfamily }
  14.  
  15.  
  16. \title{CO202: Coursework 1}
  17. \date{Autumn Term, 2019}
  18. \author{Group \#number}
  19.  
  20.  
  21. \begin{document}
  22. \maketitle
  23.  
  24. The source of this document is \texttt{Submision.lhs}, and should form the
  25. basis of your report as well as contain all the code for your submission. You
  26. should remove text (such as all the text in this section) that is here for your
  27. information only and that does not contribute to your submission.
  28. You should start by modifying the \verb|\author{}| command above to include
  29. your group number.
  30.  
  31. The source code of the provided \texttt{Submission.lhs} contains code and
  32. comments that are hidden from the final \texttt{pdf} file, so you should
  33. inspect it carefully. For instance, the code declares the use of various
  34. language features that are used in this code base. You can learn more about
  35. these language features in the language extensions section of the GHC
  36. documentation at
  37. \url{https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html}
  38. if you wish, but for the most part you need not worry about them.
  39. \begin{comment}
  40. The code in commented blocks such as this one is required for this file to
  41. compile.
  42. \begin{code}
  43. {-# LANGUAGE FlexibleInstances #-}
  44. {-# LANGUAGE ScopedTypeVariables #-}
  45. {-# LANGUAGE FunctionalDependencies #-}
  46. {-# LANGUAGE GeneralizedNewtypeDeriving #-}
  47. {-# LANGUAGE StandaloneDeriving #-}
  48. {-# LANGUAGE InstanceSigs #-}
  49. {-# LANGUAGE UndecidableInstances #-}
  50. {-# LANGUAGE TypeApplications #-}
  51. \end{code}
  52. \end{comment}
  53.  
  54. The following imports various modules that are used. You should avoid depending
  55. on any libraries other than those distributed with GHC:
  56. \href{http://hackage.haskell.org/package/base}{\texttt{base}} and
  57. \href{https://hackage.haskell.org/package/containers}{\texttt{containers}}
  58. ought to contain everything you need.
  59. \begin{comment}
  60. \begin{code}
  61. module Submission where
  62.  
  63. import Prelude hiding (maximum)
  64. import Data.Maybe (fromJust)
  65. import Data.Coerce (coerce)
  66. import Data.Function (on)
  67.  
  68. import Data.Array
  69. import Data.List (nub, sortBy, maximumBy, minimumBy, tails, inits, mapAccumL, deleteBy,(\\))
  70. import Data.Map (Map)
  71. import qualified Data.Map as M
  72.  
  73. \end{code}
  74. \end{comment}
  75.  
  76. All of the necessary types and definitions from the specification of this
  77. coursework have been given to you in the source of this document. You need not repeat
  78. that code in your submission, but it is required within the \verb|\begin{code}| and \verb|\end{code}| markers so that it can be compiled.
  79.  
  80. Before submitting your coursework, you should ensure that your code compiles
  81. properly. Use the following command with the supplied
  82. \texttt{Submission.lhs-boot} file to check that it can be marked:
  83. \begin{spec}
  84. ghc -fforce-recomp -c Submission.lhs-boot Submission.lhs
  85. \end{spec}
  86. This checks to see if all the type signatures of exposed functions are as
  87. expected.
  88.  
  89.  
  90. \begin{comment}
  91. \begin{code}
  92. data Player = Player1 | Player2
  93. data Planet = Planet Owner Ships Growth
  94. newtype Ships = Ships Int
  95. newtype Growth = Growth Int
  96. data Owner = Neutral | Owned Player
  97. newtype PlanetId = PlanetId Int
  98. type Planets = Map PlanetId Planet
  99. data Wormhole = Wormhole Source Target Turns
  100.  
  101. newtype Source = Source PlanetId
  102. newtype Target = Target PlanetId
  103. newtype Turns = Turns Int
  104. newtype WormholeId = WormholeId Int
  105. type Wormholes = Map WormholeId Wormhole
  106. data Fleet = Fleet Player Ships WormholeId Turns
  107. type Fleets = [Fleet]
  108. data GameState = GameState Planets Wormholes Fleets
  109. data Order = Order WormholeId Ships
  110. \end{code}
  111. \end{comment}
  112.  
  113. \begin{comment}
  114. \begin{code}
  115. fib :: Int -> Integer
  116. fib 0 = 0
  117. fib 1 = 1
  118. fib n = fib (n-2) + fib (n-1)
  119.  
  120. fib' :: Int -> Integer
  121. fib' n = table ! n
  122. where
  123. table :: Array Int Integer
  124. table = tabulate (0, n) mfib
  125.  
  126. mfib 0 = 0
  127. mfib 1 = 1
  128. mfib n = table ! (n-1) + table ! (n-2)
  129.  
  130. tabulate :: Ix i => (i,i) -> (i -> a) -> Array i a
  131. tabulate (u,v) f = array (u,v) [ (i, f i) | i <- range (u, v)]
  132. \end{code}
  133. \end{comment}
  134.  
  135. \begin{comment}
  136. \begin{code}
  137. example1 :: GameState
  138. example1 = GameState planets wormholes fleets where
  139. planets = M.fromList
  140. [ (PlanetId 0, Planet (Owned Player1) (Ships 300) (Growth 0))
  141. , (PlanetId 1, Planet Neutral (Ships 200) (Growth 50))
  142. , (PlanetId 2, Planet Neutral (Ships 150) (Growth 10))
  143. , (PlanetId 3, Planet Neutral (Ships 30) (Growth 5))
  144. , (PlanetId 4, Planet Neutral (Ships 100) (Growth 20))
  145. ]
  146. wormholes = M.fromList
  147. [ (WormholeId 0, Wormhole homePlanet (Target 1) (Turns 1))
  148. , (WormholeId 1, Wormhole homePlanet (Target 2) (Turns 1))
  149. , (WormholeId 2, Wormhole homePlanet (Target 3) (Turns 1))
  150. , (WormholeId 3, Wormhole homePlanet (Target 4) (Turns 1))
  151. ] where homePlanet = Source 0
  152. fleets = []
  153.  
  154. targetPlanets :: GameState -> Source -> [(PlanetId, Ships, Growth)]
  155. targetPlanets st s
  156. = map (planetDetails . target) (M.elems (wormholesFrom s st))
  157. where
  158. planetDetails :: PlanetId -> (PlanetId, Ships, Growth)
  159. planetDetails pId = (pId, ships, growth)
  160. where Planet _ ships growth = lookupPlanet pId st
  161.  
  162. shipsOnPlanet :: GameState -> PlanetId -> Ships
  163. shipsOnPlanet st pId = ships
  164. where Planet _ ships _ = lookupPlanet pId st
  165.  
  166. lookupPlanet :: PlanetId -> GameState -> Planet
  167. lookupPlanet pId (GameState ps _ _) = fromJust (M.lookup pId ps)
  168.  
  169. wormholesFrom :: Source -> GameState -> Wormholes
  170. wormholesFrom pId (GameState _ ws _)
  171. = M.filter (\(Wormhole s _ _) -> s == pId) ws
  172.  
  173. wormholesTo :: Target -> GameState -> Wormholes
  174. wormholesTo pId (GameState _ ws _)
  175. = M.filter (\(Wormhole _ t _) -> t == pId) ws
  176.  
  177. knapsack :: (Ord weight, Num weight, Ord value, Num value) =>
  178. [(name, weight, value)] -> weight -> value
  179. knapsack wvs c = maximum 0 [ v + knapsack wvs (c - w) | (_,w,v) <- wvs , w <= c ]
  180.  
  181. maximum :: Ord a => a -> [a] -> a
  182. maximum x xs = foldr max x xs
  183. \end{code}
  184. \end{comment}
  185.  
  186. \marginnote{Make sure that the problems you are solving are clearly indicated.
  187. Using a section is a good idea. You should endeavor to concisely explain the
  188. code you have written. Feel free to make use of your own margin notes, and do
  189. please remove this one.}
  190. \section*{Problem 1: Dynamic Knapsack}
  191.  
  192. \begin{code}
  193. knapsack' :: forall name weight value .
  194. (Ix weight, Num weight, Ord value, Num value) =>
  195. [(name, weight, value)] -> weight -> value
  196. knapsack' wvs c = table ! c
  197. where
  198. table :: Array weight value
  199. table = tabulate (0,c) mknapsack
  200.  
  201. mknapsack :: weight -> value
  202. mknapsack c = maximum 0 [ v + table ! (c - w) | (_,w,v) <- wvs , w <= c ]
  203. \end{code}
  204.  
  205. \section*{Problem 2: Knapsack Elements}
  206.  
  207. \begin{code}
  208. knapsack'' :: forall name weight value .
  209. (Ix weight, Num weight, Ord value, Num value) =>
  210. [(name, weight, value)] -> weight -> (value, [name])
  211. knapsack'' wvs c = table ! c
  212. where
  213. table :: Array weight (value, [name])
  214. table = tabulate (0,c) mknapsack
  215.  
  216. mknapsack :: weight -> (value, [name])
  217. mknapsack c = maximumBy (compare `on` fst) vns
  218. where
  219. vns = (0, []) : [(v + v', n : es) | (n, w, v) <- wvs , w <= c, let (v', es) = table ! (c - w)]
  220. \end{code}
  221.  
  222. \section*{Problem 3: Bounded Knapsack}
  223. \begin{code}
  224. bknapsack :: (Ord weight, Num weight, Ord value, Num value)
  225. => [(name, weight, value)] -> weight -> (value, [name])
  226. bknapsack [] c = (0, [])
  227. bknapsack ((n, w, v) : xs) c
  228. | w > c = bknapsack xs c
  229. | otherwise = maximumBy (compare `on` fst) vns
  230. where
  231. vns = [(v + v', (ns ++ [n])), vn]
  232. (v', ns) = bknapsack xs (c - w)
  233. vn = bknapsack xs c
  234. \end{code}
  235.  
  236. \section*{Problem 4: Reasonable Indexes}
  237.  
  238. The tabulate function would have to not only calculate for every weight in the
  239. provided range. However, it is harder to provide it a meaningful range of lists
  240. for tabulate to understand. Moreover, the computation of every weight and list
  241. permutation will be heavy and may not be benefitial.
  242.  
  243. \section*{Problem 5: Bounded Knapsack Revisited}
  244.  
  245. \begin{code}
  246. -- bknapsack' expects to take the list size as an input
  247. bknapsack' :: forall name weight value .
  248. (Ord weight, Num weight, Ord value, Num value) =>
  249. [(name, weight, value)] -> Int ->
  250. weight -> (value, [name])
  251. bknapsack' _ 0 _ = (0, [])
  252. bknapsack' wvs i c
  253. | w > c = bknapsack' wvs (i - 1) c
  254. | otherwise = maximumBy (compare `on` fst) vns
  255. where
  256. vns = [(v + v', (n : ns)), vn]
  257. (n, w, v) = wvs !! (i - 1)
  258. (v', ns) = bknapsack' wvs (i - 1) (c - w)
  259. vn = bknapsack' wvs (i - 1) c
  260. \end{code}
  261.  
  262. \section*{Problem 6: Dynamic Bounded Knapsack}
  263.  
  264. \begin{code}
  265. bknapsack'' :: forall name weight value .
  266. (Ord name, Ix weight, Ord weight, Num weight,
  267. Ord value, Num value) =>
  268. [(name, weight, value)] -> weight -> (value, [name])
  269. bknapsack'' wvs c = table ! (listSize, c)
  270. where
  271. listSize = length wvs
  272.  
  273. table :: Array (Int, weight) (value, [name])
  274. table = tabulate ((0, 0), (listSize, c)) mbknapsack''
  275.  
  276. mbknapsack'' :: (Int, weight) -> (value, [name])
  277. mbknapsack'' (0, _) = (0, [])
  278. mbknapsack'' (i, c')
  279. | w > c' = table ! (i - 1, c')
  280. | otherwise = maximumBy (compare `on` fst) vns
  281. where
  282. vns = [(v + v', (n : ns)), vn]
  283. (n, w, v) = wvs !! (i - 1)
  284. (v', ns) = table ! (i - 1, c' - w)
  285. vn = table ! (i - 1, c')
  286. \end{code}
  287.  
  288. \section*{Problem 7: Dijkstra Dualized}
  289.  
  290. \begin{comment}
  291. \begin{code}
  292. optimise :: GameState -> Source -> (Growth, [PlanetId])
  293. optimise st s@(Source p) = bknapsack'' (targetPlanets st s) (shipsOnPlanet st p)
  294.  
  295. type Weight = Integer
  296.  
  297. class Eq v => Edge e v | e -> v where
  298. source :: e -> v
  299. target :: e -> v
  300. weight :: e -> Weight
  301.  
  302. instance Edge (String, String, Integer) String where
  303. source (s, _, _) = s
  304. target (_, t, _) = t
  305. weight (_, _, i) = i
  306.  
  307. instance Edge Wormhole PlanetId where
  308. source (Wormhole (Source s) _ _) = s
  309. target (Wormhole _ (Target t) _) = t
  310. weight (Wormhole _ _ (Turns turns)) = toInteger turns
  311.  
  312. instance Edge (WormholeId, Wormhole) PlanetId where
  313. source (_, w) = source w
  314. target (_, w) = target w
  315. weight (_, w) = weight w
  316.  
  317. data Path e = Path Weight [e]
  318. \end{code}
  319.  
  320. \begin{code}
  321. pathFromEdge :: Edge e v => e -> Path e
  322. pathFromEdge e = Path (weight e) [e]
  323. \end{code}
  324.  
  325. \begin{code}
  326. extend :: Edge e v => Path e -> e -> Path e
  327. extend (Path _ []) _ = error "extend: Empty path"
  328. extend (Path d (e:es)) e'
  329. | target e == source e' = Path (d + weight e') (e':e:es)
  330. | otherwise = error "extend: Incompatible endpoints"
  331. \end{code}
  332.  
  333. \begin{code}
  334. pathFromEdges :: Edge e v => [e] -> Path e
  335. pathFromEdges (x : xs) = foldl extend (pathFromEdge x) xs
  336. pathFromEdges [] = error "pathFromEdges: Empty list of edges"
  337. \end{code}
  338.  
  339. \begin{code}
  340. instance Edge e v => Edge (Path e) v where
  341. source (Path _ es) = source (last es)
  342. target (Path _ es) = target (head es)
  343. weight (Path w _) = w
  344. \end{code}
  345.  
  346. \begin{code}
  347. class Edge e v => Graph g e v | g -> e where
  348. vertices :: g -> [v]
  349. edges :: g -> [e]
  350. edgesFrom :: g -> v -> [e]
  351. edgesTo :: g -> v -> [e]
  352. velem :: v -> g -> Bool
  353. eelem :: e -> g -> Bool
  354. \end{code}
  355.  
  356. \begin{code}
  357. instance (Eq e, Edge e v) => Graph [e] e v where
  358. vertices es = nub (map source es ++ map target es)
  359. edges es = es
  360. edgesFrom es v = [ e | e <- es, v == source e ]
  361. edgesTo es v = [ e | e <- es, v == target e ]
  362. velem v es = v `elem` vertices es
  363. eelem v es = v `elem` edges es
  364. \end{code}
  365.  
  366. \begin{code}
  367. example2 :: [(String, String, Integer)]
  368. example2 = [("s","t",10), ("s","y",5), ("t","x",1), ("t","y",2), ("y","t",3),
  369. ("y","x", 9), ("x","z",4), ("z","x",6), ("y","z",2), ("z","s",7)]
  370. \end{code}
  371.  
  372. \begin{code}
  373. instance Graph GameState (WormholeId, Wormhole) PlanetId where
  374. vertices (GameState ps _ _) = M.keys ps
  375. edges (GameState _ ws _) = M.assocs ws
  376. edgesTo st pId = M.toList (wormholesTo (Target pId) st)
  377. edgesFrom st pId = M.toList (wormholesFrom (Source pId) st)
  378. velem pId (GameState ps _ _) = M.member pId ps
  379. eelem (wId, _) (GameState _ ws _) = M.member wId ws
  380. \end{code}
  381. \end{comment}
  382.  
  383. \begin{comment}
  384. \begin{code}
  385. lte :: (a -> a -> Ordering) -> (a -> a -> Bool)
  386. lte cmp x y = cmp x y /= GT
  387.  
  388. eq :: (a -> a -> Ordering) -> (a -> a -> Bool)
  389. eq cmp x y = cmp x y == EQ
  390. \end{code}
  391.  
  392. \begin{code}
  393. class PQueue pqueue where
  394. toPQueue :: (a -> a -> Ordering) -> [a] -> pqueue a
  395. fromPQueue :: pqueue a -> [a]
  396.  
  397. priority :: pqueue a -> (a -> a -> Ordering)
  398.  
  399. empty :: (a -> a -> Ordering) -> pqueue a
  400. isEmpty :: pqueue a -> Bool
  401.  
  402. insert :: a -> pqueue a -> pqueue a
  403. delete :: a -> pqueue a -> pqueue a
  404.  
  405. extract :: pqueue a -> a
  406. discard :: pqueue a -> pqueue a
  407. detach :: pqueue a -> (a, pqueue a)
  408.  
  409. data PList a = PList (a -> a -> Ordering) [a]
  410.  
  411. instance PQueue PList where
  412.  
  413. toPQueue cmp xs = PList cmp (sortBy cmp xs)
  414.  
  415. fromPQueue (PList _ xs) = xs
  416.  
  417. empty cmp = PList cmp []
  418.  
  419. isEmpty (PList _ xs) = null xs
  420.  
  421. priority (PList cmp _) = cmp
  422.  
  423. insert x (PList cmp []) = PList cmp [x]
  424. insert x ps@(PList cmp xs)
  425. | x <= y = cons x ps
  426. | otherwise = cons y (insert x ys)
  427. where (<=) = lte cmp
  428. (y, ys) = detach ps
  429. cons x (PList cmp xs) = PList cmp (x:xs)
  430.  
  431. delete x (PList cmp []) = PList cmp []
  432. delete x ps@(PList cmp _)
  433. | x == y = ys
  434. | otherwise = cons y (delete x ys)
  435. where (==) = eq cmp
  436. (y, ys) = detach ps
  437. cons x (PList cmp xs) = PList cmp (x:xs)
  438.  
  439. extract (PList cmp (x:xs)) = x
  440.  
  441. discard (PList cmp (x:xs)) = PList cmp xs
  442.  
  443. detach (PList cmp (x:xs)) = (x, PList cmp xs)
  444.  
  445. cmpPath :: Path v -> Path v -> Ordering
  446. cmpPath (Path d _) (Path d' _) = compare d d'
  447. \end{code}
  448. \end{comment}
  449.  
  450. \begin{comment}
  451. \begin{code}
  452. shortestPaths :: forall g e v. Graph g e v => g -> v -> [Path e]
  453. shortestPaths g v = dijkstra g (vertices g \\ [v]) ps
  454. where
  455. ps :: PList (Path e)
  456. ps = foldr insert (empty cmpPath) (map pathFromEdge (edgesFrom g v))
  457. \end{code}
  458.  
  459. \begin{code}
  460. example3 :: GameState
  461. example3 = GameState planets wormholes fleets where
  462. planets = M.fromList
  463. [ (PlanetId 0, Planet (Owned Player1) (Ships 300) (Growth 0))
  464. , (PlanetId 1, Planet Neutral (Ships 200) (Growth 50))
  465. , (PlanetId 2, Planet Neutral (Ships 150) (Growth 10))
  466. , (PlanetId 3, Planet Neutral (Ships 30) (Growth 5))
  467. , (PlanetId 4, Planet Neutral (Ships 100) (Growth 20))
  468. , (PlanetId 5, Planet Neutral (Ships 100) (Growth 20))
  469. ]
  470. wormholes = M.fromList
  471. [ (WormholeId 0, Wormhole homePlanet (Target 1) (Turns 1))
  472. , (WormholeId 1, Wormhole homePlanet (Target 2) (Turns 2))
  473. , (WormholeId 2, Wormhole homePlanet (Target 3) (Turns 3))
  474. , (WormholeId 3, Wormhole homePlanet (Target 4) (Turns 4))
  475. , (WormholeId 4, Wormhole (Source 4) (Target 5) (Turns 1))
  476. , (WormholeId 5, Wormhole (Source 2) (Target 5) (Turns 1))
  477. ] where homePlanet = Source 0
  478. fleets = []
  479. \end{code}
  480.  
  481. \begin{code}
  482. dijkstra :: (Graph g e v, PQueue pqueue) =>
  483. g -> [v] -> pqueue (Path e) -> [Path e]
  484. dijkstra g [] ps = []
  485. dijkstra g us ps
  486. | isEmpty ps = []
  487. | v `elem` us = p : dijkstra g (us \\ [v])
  488. (foldr insert ps' (map (extend p) (edgesFrom g v)))
  489. | otherwise = dijkstra g us ps'
  490. where
  491. (p, ps') = detach ps
  492. v = target p
  493. \end{code}
  494. \end{comment}
  495.  
  496. \section*{Problem 8: Heap Operations}
  497.  
  498.  
  499. \begin{code}
  500. data Heap a = Heap (a -> a -> Ordering) (Tree a)
  501. data Tree a = Nil | Node Int (Tree a) a (Tree a)
  502.  
  503. instance PQueue Heap where
  504. toPQueue = undefined
  505. fromPQueue = undefined
  506.  
  507. priority :: Heap a -> (a -> a -> Ordering)
  508. priority = undefined
  509.  
  510. empty :: (a -> a -> Ordering) -> Heap a
  511. empty p = undefined
  512.  
  513. isEmpty :: Heap a -> Bool
  514. isEmpty = undefined
  515.  
  516. insert :: a -> Heap a -> Heap a
  517. insert = undefined
  518.  
  519. delete :: a -> Heap a -> Heap a
  520. delete = undefined
  521.  
  522. extract :: Heap a -> a
  523. extract = undefined
  524.  
  525. discard :: Heap a -> Heap a
  526. discard = undefined
  527.  
  528. detach :: Heap a -> (a, Heap a)
  529. detach = undefined
  530. \end{code}
  531.  
  532. \begin{comment}
  533. \begin{code}
  534. shortestPaths' :: forall g e v . Graph g e v => g -> v -> [Path e]
  535. shortestPaths' g v = dijkstra g (vertices g) ps
  536. where
  537. ps :: Heap (Path e)
  538. ps = foldr insert (empty cmpPath) (map pathFromEdge (edgesFrom g v))
  539. \end{code}
  540. \end{comment}
  541.  
  542. \section*{Problem 9: Adjacency List Graphs}
  543.  
  544. \begin{code}
  545. newtype AdjList e v = AdjList [(v, [e])]
  546.  
  547. instance (Eq e, Edge e v) => Graph (AdjList e v) e v where
  548. vertices (AdjList ves) = undefined
  549. edges (AdjList ves) = undefined
  550. edgesFrom (AdjList ves) s = undefined
  551. edgesTo (AdjList ves) t = undefined
  552. velem v (AdjList ves) = undefined
  553. eelem e (AdjList ves) = undefined
  554. \end{code}
  555.  
  556. \section*{Problem 10: Conflict Zones}
  557.  
  558. \begin{code}
  559. conflictZones :: GameState -> PlanetId -> PlanetId
  560. -> ([PlanetId], [PlanetId], [PlanetId])
  561. conflictZones g p q = undefined
  562. \end{code}
  563.  
  564. \begin{comment}
  565. \begin{code}
  566. deriving instance Show Player
  567. deriving instance Read Player
  568. deriving instance Show Owner
  569. deriving instance Read Owner
  570. deriving instance Show Planet
  571. deriving instance Read Planet
  572. deriving instance Show Fleet
  573. deriving instance Read Fleet
  574.  
  575. deriving instance Show Wormhole
  576. deriving instance Read Wormhole
  577.  
  578. deriving instance Show Order
  579. deriving instance Read Order
  580. deriving instance Show GameState
  581. deriving instance Read GameState
  582.  
  583. deriving instance Ord PlanetId
  584. deriving instance Eq PlanetId
  585. deriving instance Num PlanetId
  586. instance Show PlanetId where
  587. show (PlanetId x) = show x
  588. instance Read PlanetId where
  589. readsPrec = coerce (readsPrec @Int)
  590.  
  591. deriving instance Ord Turns
  592. deriving instance Eq Turns
  593. deriving instance Num Turns
  594. instance Show Turns where
  595. show (Turns x) = show x
  596. instance Read Turns where
  597. readsPrec = coerce (readsPrec @Int)
  598.  
  599. deriving instance Ord Source
  600. deriving instance Eq Source
  601. instance Show Source where
  602. show (Source x) = show x
  603. instance Read Source where
  604. readsPrec = coerce (readsPrec @Int)
  605.  
  606. deriving instance Num Growth
  607. deriving instance Ord Growth
  608. deriving instance Eq Growth
  609. instance Show Growth where
  610. show (Growth x) = show x
  611. instance Read Growth where
  612. readsPrec = coerce (readsPrec @Int)
  613.  
  614. deriving instance Ix Ships
  615. deriving instance Num Ships
  616. deriving instance Ord Ships
  617. deriving instance Eq Ships
  618. instance Show Ships where
  619. show (Ships x) = show x
  620. instance Read Ships where
  621. readsPrec = coerce (readsPrec @Int)
  622.  
  623. deriving instance Ord Target
  624. deriving instance Eq Target
  625. instance Show Target where
  626. show (Target x) = show x
  627. instance Read Target where
  628. readsPrec = coerce (readsPrec @Int)
  629.  
  630. deriving instance Eq WormholeId
  631. deriving instance Ord WormholeId
  632. instance Show WormholeId where
  633. show (WormholeId x) = show x
  634. instance Read WormholeId where
  635. readsPrec = coerce (readsPrec @Int)
  636.  
  637. deriving instance Eq e => Eq (Path e)
  638. deriving instance Show e => Show (Path e)
  639. instance Show a => Show (PList a) where
  640. show (PList _ xs) = show xs
  641.  
  642. \end{code}
  643. \end{comment}
  644.  
  645. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement