1{-# language ScopedTypeVariables #-}
2{-# language StandaloneKindSignatures #-}
3{-# language TypeApplications #-}
4{-# language ViewPatterns #-}
6module Rel8.Type.ReadShow ( ReadShow(..) ) where
9import Data.Kind ( Type )
10import Data.Proxy ( Proxy( Proxy ) )
11import Data.Typeable ( Typeable, typeRep )
13import Text.Read ( readMaybe )
16import Rel8.Type ( DBType( typeInformation ) )
17import Rel8.Type.Information ( parseTypeInformation )
20import qualified Data.Text as Text
23-- | A deriving-via helper type for column types that store a Haskell value
24-- using a Haskell's 'Read' and 'Show' type classes.
25type ReadShow :: Type -> Type
26newtype ReadShow a = ReadShow { fromReadShow :: a }
29instance (Read a, Show a, Typeable a) => DBType (ReadShow a) where
30 typeInformation = parseTypeInformation parser printer typeInformation
32 parser (Text.unpack -> t) = case readMaybe t of
33 Just ok -> Right $ ReadShow ok
34 Nothing -> Left $ "Could not read " <> t <> " as a " <> show (typeRep (Proxy @a))
35 printer = Text.pack . show . fromReadShow
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list