Updated TyVarBndr usage; removed redundant Instances; added Word24 wrapper instead of not compiling Word24 library.

This commit is contained in:
Stephan Barth 2024-01-25 02:18:39 +01:00
parent 6601eb600b
commit 1c0654041f
3 changed files with 58 additions and 9 deletions

View File

@ -1,4 +1,4 @@
-- SPDX-FileCopyrightText: 2022 Gregor Kleen <gregor.kleen@ifi.lmu.de>,Sarah Vaupel <vaupel.sarah@campus.lmu.de>
-- SPDX-FileCopyrightText: 2024 Stephan Barth <stephan.barth@uniworx.de>, 2022 Gregor Kleen <gregor.kleen@ifi.lmu.de>,Sarah Vaupel <vaupel.sarah@campus.lmu.de>
--
-- SPDX-License-Identifier: AGPL-3.0-or-later
@ -24,13 +24,14 @@ import Data.Containers.ListUtils
import Control.Lens hiding (universe)
import Data.Generics.Product.Types
--import Language.Haskell.TH.Datatype.TyVarBndr
-- | Get type var bind name
--
-- Stolen from https://hackage.haskell.org/package/template-haskell-util-0.1.1.0
getTVBName :: TyVarBndr -> Name
getTVBName (PlainTV name ) = name
getTVBName (KindedTV name _) = name
-- Stolen from https://hackage.haskell.org/package/template-haskell-util-0.1.1.0; modified by Stephan Barth
getTVBName :: TyVarBndr flag -> Name
getTVBName (PlainTV name _) = name
getTVBName (KindedTV name _ _) = name

View File

@ -10,10 +10,10 @@ module Data.Void.Instances
import ClassyPrelude.Yesod
import Data.Void
instance ToContent Void where
toContent = absurd
instance ToTypedContent Void where
toTypedContent = absurd
--instance ToContent Void where
-- toContent = absurd
--instance ToTypedContent Void where
-- toTypedContent = absurd
instance RenderMessage site Void where
renderMessage _ _ = absurd

48
src/Data/Word/Word24.hs Normal file
View File

@ -0,0 +1,48 @@
module Data.Word.Word24
( Word24
) where
import Data.Word
import Import.NoModel
import Data.Bits
newtype Word24 = Word24 Word32
maxWord24 :: Num a => a
maxWord24 = 16777215
instance Bounded Word24 where
minBound = 0
maxBound = maxWord24
word24 :: Word32 -> Word24
word24 = assert (maxWord24 == 2^24-1) (Word24 . (.&. maxWord24))
instance Num Word24 where
(+) (Word24 a) (Word24 b) = word24 (a + b)
(*) (Word24 a) (Word24 b) = word24 (a * b)
abs (Word24 a) = word24 (abs a)
signum (Word24 a) = word24 (signum a)
fromInteger i = word24 (fromInteger i)
negate (Word24 a) = word24 (negate a)
instance Eq Word24 where
(==) (Word24 a) (Word24 b) = a == b
instance Ord Word24 where
compare (Word24 a) (Word24 b) = compare a b
instance Real Word24 where
toRational (Word24 a) = toRational a
instance Enum Word24 where
toEnum k = word24 (toEnum k)
fromEnum (Word24 k) = fromEnum k
instance Integral Word24 where
quotRem (Word24 a) (Word24 b) =
let (u,v) = quotRem a b in
(word24 u, word24 v)
toInteger (Word24 w) = toInteger w