aboutsummaryrefslogtreecommitdiff
path: root/spec/src/Thermoprint/Printout.hs
diff options
context:
space:
mode:
authorGregor Kleen <pngwjpgh@users.noreply.github.com>2016-07-17 19:21:56 +0200
committerGregor Kleen <pngwjpgh@users.noreply.github.com>2016-07-17 19:21:56 +0200
commit2b9ceaead3f3cd80e973cccecb9a3eebc51154f7 (patch)
treedf2378943480647606b6a06f62c0f4b8b2ab406d /spec/src/Thermoprint/Printout.hs
parentac4cf4a0a494eafe55364f816569c517684fdf32 (diff)
downloadthermoprint-2b9ceaead3f3cd80e973cccecb9a3eebc51154f7.tar
thermoprint-2b9ceaead3f3cd80e973cccecb9a3eebc51154f7.tar.gz
thermoprint-2b9ceaead3f3cd80e973cccecb9a3eebc51154f7.tar.bz2
thermoprint-2b9ceaead3f3cd80e973cccecb9a3eebc51154f7.tar.xz
thermoprint-2b9ceaead3f3cd80e973cccecb9a3eebc51154f7.zip
Fixes for GHC 8.0.1
Diffstat (limited to 'spec/src/Thermoprint/Printout.hs')
-rw-r--r--spec/src/Thermoprint/Printout.hs42
1 files changed, 35 insertions, 7 deletions
diff --git a/spec/src/Thermoprint/Printout.hs b/spec/src/Thermoprint/Printout.hs
index 2be0a83..8c33e07 100644
--- a/spec/src/Thermoprint/Printout.hs
+++ b/spec/src/Thermoprint/Printout.hs
@@ -1,6 +1,6 @@
1{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-} 1{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}
2{-# LANGUAGE OverloadedStrings #-} 2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-} 3{-# LANGUAGE FlexibleInstances, FlexibleContexts, UndecidableInstances #-}
4{-# OPTIONS_HADDOCK show-extensions #-} 4{-# OPTIONS_HADDOCK show-extensions #-}
5 5
6-- | This module contains the definition of the structure -- 'Printout' -- used to represent the content of a job 6-- | This module contains the definition of the structure -- 'Printout' -- used to represent the content of a job
@@ -63,19 +63,47 @@ import Prelude hiding (fold)
63 63
64 64
65-- | A 'Printout' is a sequence of visually seperated 'Paragraph's 65-- | A 'Printout' is a sequence of visually seperated 'Paragraph's
66type Printout = Seq Paragraph 66newtype Printout = Printout { getParagraphs :: Seq Paragraph }
67 deriving (Show, Generic, NFData)
68
69instance Eq Paragraph => Eq Printout where
70 (==) = (==) `on` getParagraphs
71
72instance Monoid Printout where
73 mempty = Printout mempty
74 mappend a b = Printout $ (mappend `on` getParagraphs) a b
75
76instance FromJSON Printout where
77 parseJSON = fmap Printout . parseJSON
78
79instance ToJSON Printout where
80 toJSON = toJSON . getParagraphs
81
82instance Arbitrary Printout where
83 arbitrary = Printout <$> arbitrary
67 84
68-- | A 'Paragraph' is a non-seperated sequence of 'Chunk's 85-- | A 'Paragraph' is a non-seperated sequence of 'Chunk's
69type Paragraph = Seq Chunk 86newtype Paragraph = Paragraph { getChunks :: Seq Chunk }
87 deriving (Show, Generic, NFData)
88
89instance Eq Chunk => Eq Paragraph where
90 (==) = (==) `on` getChunks
91
92instance Monoid Paragraph where
93 mempty = Paragraph mempty
94 mappend a b = Paragraph $ (mappend `on` getChunks) a b
95
96instance Arbitrary Paragraph where
97 arbitrary = Paragraph <$> arbitrary
70 98
71instance FromJSON Paragraph where 99instance FromJSON Paragraph where
72 parseJSON o@(Array _) = Seq.fromList <$> parseJSON o 100 parseJSON o@(Array _) = Paragraph . Seq.fromList <$> parseJSON o
73 parseJSON o@(Object _) = Seq.singleton <$> parseJSON o 101 parseJSON o@(Object _) = Paragraph . Seq.singleton <$> parseJSON o
74 parseJSON o@(String _) = Seq.singleton <$> parseJSON o 102 parseJSON o@(String _) = Paragraph . Seq.singleton <$> parseJSON o
75 parseJSON v = typeMismatch "Paragraph" v 103 parseJSON v = typeMismatch "Paragraph" v
76 104
77instance ToJSON Paragraph where 105instance ToJSON Paragraph where
78 toJSON cs 106 toJSON (Paragraph cs)
79 | (a :< as) <- viewl cs 107 | (a :< as) <- viewl cs
80 , Seq.null as = toJSON a 108 , Seq.null as = toJSON a
81 | otherwise = toJSON $ toList cs 109 | otherwise = toJSON $ toList cs