on master help sign in
Overloaded literals
commitb8797b8bf6dd83a227a947bf825d88ff2f82d502 authorDenis Redozubov <denis.redozubov@gmail.com> dateThu 12 Oct 2017, 15:42 (9 years ago) parent1190166
1 file changed+17
src/Data/Schematic/Schema.hs+17
src/Data/Schematic/Schema.hs+17
@@ -22,6 +22,7 @@ import Data.Union
2222import Data.Vector as V
2323import Data.Vinyl hiding (Dict)
2424import qualified Data.Vinyl.TypeLevel as V
25+import GHC.Exts
2526import GHC.Generics (Generic)
2627import GHC.TypeLits (SomeNat(..), SomeSymbol(..), someSymbolVal, someNatVal)
2728import Prelude as P
@@ -392,6 +393,22 @@ instance Eq (JsonRepr s) => Eq (JsonRepr ('SchemaArray as s)) where
392393instance Eq (JsonRepr s) => Eq (JsonRepr ('SchemaOptional s)) where
393394 ReprOptional a == ReprOptional b = a == b
394395
396+instance IsList (JsonRepr ('SchemaArray cs s)) where
397+ type Item (JsonRepr ('SchemaArray cs s)) = JsonRepr s
398+ fromList = ReprArray . GHC.Exts.fromList
399+ toList (ReprArray v) = GHC.Exts.toList v
400+
401+instance Num (JsonRepr ('SchemaNumber cs)) where
402+ ReprNumber a + ReprNumber b = ReprNumber $ a + b
403+ ReprNumber a - ReprNumber b = ReprNumber $ a - b
404+ ReprNumber a * ReprNumber b = ReprNumber $ a * b
405+ abs (ReprNumber a) = ReprNumber $ abs a
406+ signum (ReprNumber a) = ReprNumber $ signum a
407+ fromInteger = ReprNumber . fromIntegral
408+
409+instance IsString (JsonRepr ('SchemaText cs)) where
410+ fromString = ReprText . fromString
411+
395412fromOptional
396413 :: SingI s
397414 => Sing ('SchemaOptional s)