From 7885042246ac4a08e0f7b3ba27a7691a4908f3b6 Mon Sep 17 00:00:00 2001
From: Gregor Kleen <gkleen@yggdrasil.li>
Date: Tue, 15 May 2018 15:30:53 +0200
Subject: Fix read/show

---
 src/Trivmix/Types.hs | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

(limited to 'src')

diff --git a/src/Trivmix/Types.hs b/src/Trivmix/Types.hs
index f01e023..abfdc43 100644
--- a/src/Trivmix/Types.hs
+++ b/src/Trivmix/Types.hs
@@ -62,7 +62,7 @@ dBToLin :: Float -> Level'
 dBToLin x = either error id . refine $ 10 ** (0.05 * x)
 
 instance Show Level where
-  show (Lin x) = show x
+  show (Lin (unrefine -> x)) = show x
   show (DB (linToDb -> x)) = (show $ (withPrec x :: Milli)) ++ "dB"
 
 instance Read Level where
@@ -75,7 +75,9 @@ instance Read Level where
         unit' <- forM [1..lU] $ const get
         guard $ ((==) `on` CI.mk) unit unit'
         return . DB $ dBToLin db
-      parseLin = Lin <$> readS_to_Prec readsPrec
+      parseLin = do
+        lin <- readS_to_Prec readsPrec
+        either (const mzero) (return . Lin) $ refine lin
 
 instance Eq Level where
   (==) = (==) `on` toLin
-- 
cgit v1.2.3