Skip to content

Commit

Permalink
Implement 'deepErrorX' in terms of 'spinify'
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnbastiaan committed Sep 17, 2019
1 parent 695a25a commit c6b5181
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions clash-prelude/src/Clash/XException.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import GHC.Exts (Char (C#), Double (D#), Float (F#), Int (I#), Word (W#
import GHC.Generics
import GHC.Natural (Natural)
import GHC.Show (appPrec)
import GHC.Stack (HasCallStack, callStack, prettyCallStack, withFrozenCallStack)
import GHC.Stack (HasCallStack, callStack, prettyCallStack)
import Numeric.Half (Half)
import System.IO.Unsafe (unsafeDupablePerformIO)

Expand Down Expand Up @@ -575,8 +575,8 @@ class NFDataX a where
-- is defined.
deepErrorX :: HasCallStack => String -> a

default deepErrorX :: (HasCallStack, Generic a, GDeepErrorX (Rep a)) => String -> a
deepErrorX = withFrozenCallStack $ to . gDeepErrorX
default deepErrorX :: HasCallStack => String -> a
deepErrorX s = spinify (errorX s)

-- | Create a value where at the very least the spine is defined. For example:
--
Expand Down Expand Up @@ -761,24 +761,3 @@ instance NFDataX a => NFDataX (SG.Min a)
instance NFDataX a => NFDataX (SG.Option a)
instance NFDataX a => NFDataX (SG.Product a)
instance NFDataX a => NFDataX (SG.Sum a)

class GDeepErrorX f where
gDeepErrorX :: HasCallStack => String -> f a

instance GDeepErrorX V1 where
gDeepErrorX = errorX

instance GDeepErrorX U1 where
gDeepErrorX = const U1

instance (GDeepErrorX a) => GDeepErrorX (M1 m d a) where
gDeepErrorX e = M1 (gDeepErrorX e)

instance (GDeepErrorX f, GDeepErrorX g) => GDeepErrorX (f :*: g) where
gDeepErrorX e = gDeepErrorX e :*: gDeepErrorX e

instance NFDataX c => GDeepErrorX (K1 i c) where
gDeepErrorX e = K1 (deepErrorX e)

instance GDeepErrorX (f :+: g) where
gDeepErrorX = errorX

0 comments on commit c6b5181

Please sign in to comment.