copilot-core 3.16.1 → 3.17
raw patch · 5 files changed
+56/−11 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Copilot.Core.Type: accessorName :: forall a s t. (Struct a, KnownSymbol s) => (a -> Field s t) -> String
+ Copilot.Core.Type: fieldName :: forall s t. KnownSymbol s => Field s t -> String
+ Copilot.Core.Type: typeLength :: forall n t. KnownNat n => Type (Array n t) -> Int
+ Copilot.Core.Type: typeName :: Struct a => a -> String
+ Copilot.Core.Type: typeSize :: forall n t. KnownNat n => Type (Array n t) -> Int
+ Copilot.Core.Type.Array: arrayElems :: Array n a -> [a]
Files
- CHANGELOG +4/−0
- copilot-core.cabal +1/−1
- src/Copilot/Core/Type.hs +41/−6
- src/Copilot/Core/Type/Array.hs +7/−1
- tests/Test/Copilot/Core/Type/Array.hs +3/−3
CHANGELOG view
@@ -1,3 +1,7 @@+2023-11-07+ * Version bump (3.17). (#466)+ * Compliance with style guide. (#457)+ 2023-09-07 * Version bump (3.16.1). (#455)
copilot-core.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: copilot-core-version: 3.16.1+version: 3.17 synopsis: An intermediate representation for Copilot. description: Intermediate representation for Copilot.
src/Copilot/Core/Type.hs view
@@ -23,16 +23,21 @@ , UType (..) , SimpleType (..) + , typeSize , tysize+ , typeLength , tylength , Value (..) , toValues , Field (..)+ , typeName , typename , Struct+ , fieldName , fieldname+ , accessorName , accessorname ) where@@ -50,11 +55,19 @@ -- Internal imports import Copilot.Core.Type.Array (Array) +{-# DEPRECATED typename "Use typeName instead." #-}+ -- | The value of that is a product or struct, defined as a constructor with -- several fields. class Struct a where -- | Returns the name of struct in the target language.+ typeName :: a -> String+ typeName = typename++ -- | Returns the name of struct in the target language. typename :: a -> String+ typename = typeName+ -- | Transforms all the struct's fields into a list of values. toValues :: a -> [Value a] @@ -67,17 +80,29 @@ data Field (s :: Symbol) t = Field t -- | Extract the name of a field.+fieldName :: forall s t . KnownSymbol s => Field s t -> String+fieldName _ = symbolVal (Proxy :: Proxy s)++{-# DEPRECATED fieldname "Use fieldName instead." #-}+-- | Extract the name of a field. fieldname :: forall s t . KnownSymbol s => Field s t -> String-fieldname _ = symbolVal (Proxy :: Proxy s)+fieldname = fieldName -- | Extract the name of an accessor (a function that returns a field of a -- struct).+accessorName :: forall a s t . (Struct a, KnownSymbol s)+ => (a -> Field s t) -> String+accessorName _ = symbolVal (Proxy :: Proxy s)++{-# DEPRECATED accessorname "Use accessorName instead." #-}+-- | Extract the name of an accessor (a function that returns a field of a+-- struct). accessorname :: forall a s t . (Struct a, KnownSymbol s) => (a -> Field s t) -> String-accessorname _ = symbolVal (Proxy :: Proxy s)+accessorname = accessorName instance (KnownSymbol s, Show t) => Show (Field s t) where- show f@(Field v) = fieldname f ++ ":" ++ show v+ show f@(Field v) = fieldName f ++ ":" ++ show v instance {-# OVERLAPPABLE #-} (Typed t, Struct t) => Show t where show t = "<" ++ fields ++ ">"@@ -109,13 +134,23 @@ Struct :: (Typed a, Struct a) => a -> Type a -- | Return the length of an array from its type+typeLength :: forall n t . KnownNat n => Type (Array n t) -> Int+typeLength _ = fromIntegral $ natVal (Proxy :: Proxy n)++{-# DEPRECATED tylength "Use typeLength instead." #-}+-- | Return the length of an array from its type tylength :: forall n t . KnownNat n => Type (Array n t) -> Int-tylength _ = fromIntegral $ natVal (Proxy :: Proxy n)+tylength = typeLength -- | Return the total (nested) size of an array from its type+typeSize :: forall n t . KnownNat n => Type (Array n t) -> Int+typeSize ty@(Array ty'@(Array _)) = typeLength ty * typeSize ty'+typeSize ty@(Array _ ) = typeLength ty++{-# DEPRECATED tysize "Use typeSize instead." #-}+-- | Return the total (nested) size of an array from its type tysize :: forall n t . KnownNat n => Type (Array n t) -> Int-tysize ty@(Array ty'@(Array _)) = tylength ty * tysize ty'-tysize ty@(Array _ ) = tylength ty+tysize = typeSize instance TestEquality Type where testEquality Bool Bool = Just DE.Refl
src/Copilot/Core/Type/Array.hs view
@@ -13,6 +13,7 @@ module Copilot.Core.Type.Array ( Array , array+ , arrayElems , arrayelems ) where@@ -39,6 +40,11 @@ errmsg = "Length of data (" ++ show datalen ++ ") does not match length of type (" ++ show typelen ++ ")." +-- | Return the elements of an array.+arrayElems :: Array n a -> [a]+arrayElems (Array xs) = xs++{-# DEPRECATED arrayelems "Use ArrayElems instead." #-} -- | Return the elemts of an array. arrayelems :: Array n a -> [a]-arrayelems (Array xs) = xs+arrayelems = arrayElems
tests/Test/Copilot/Core/Type/Array.hs view
@@ -13,7 +13,7 @@ vectorOf) -- Internal imports: library modules being tested-import Copilot.Core.Type.Array (Array, array, arrayelems)+import Copilot.Core.Type.Array (Array, array, arrayElems) -- | All unit tests for copilot-core:Copilot.Core.Array. tests :: Test.Framework.Test@@ -30,13 +30,13 @@ -- * Individual tests -- | Test that building an array from a list and extracting the elements with--- the function 'arrayelems' will result in the same list.+-- the function 'arrayElems' will result in the same list. testArrayElemsLeft :: forall n . KnownNat n => Proxy n -> Property testArrayElemsLeft len = forAll xsInt64 $ \ls -> let array' :: Array n Int64 array' = array ls- in arrayelems array' == ls+ in arrayElems array' == ls where