mirror of
https://github.com/github/semantic.git
synced 2024-12-22 06:11:49 +03:00
Define a function to construct singleton tables.
This commit is contained in:
parent
a827e8d331
commit
90b0475b1a
@ -1,5 +1,6 @@
|
|||||||
module Data.Syntax.Assignment.Table.Array
|
module Data.Syntax.Assignment.Table.Array
|
||||||
( Table(tableAddresses)
|
( Table(tableAddresses)
|
||||||
|
, tableSingleton
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Array
|
import Data.Array
|
||||||
@ -9,6 +10,9 @@ import Data.Functor.Classes
|
|||||||
data Table i a = Table { tableAddresses :: [i], tableBranches :: Array i (Maybe a) }
|
data Table i a = Table { tableAddresses :: [i], tableBranches :: Array i (Maybe a) }
|
||||||
deriving (Foldable, Functor, Traversable)
|
deriving (Foldable, Functor, Traversable)
|
||||||
|
|
||||||
|
tableSingleton :: Ix i => i -> a -> Table i a
|
||||||
|
tableSingleton i a = Table [i] (listArray (i, i) [Just a])
|
||||||
|
|
||||||
|
|
||||||
instance (Ix i, Show i) => Show1 (Table i) where
|
instance (Ix i, Show i) => Show1 (Table i) where
|
||||||
liftShowsPrec spA slA d Table{..} = showsBinaryWith showsPrec (const (liftShowList spA slA)) "Table" d tableAddresses (tableAddresses >>= \ addr -> (,) addr <$> toList (tableBranches ! addr))
|
liftShowsPrec spA slA d Table{..} = showsBinaryWith showsPrec (const (liftShowList spA slA)) "Table" d tableAddresses (tableAddresses >>= \ addr -> (,) addr <$> toList (tableBranches ! addr))
|
||||||
|
Loading…
Reference in New Issue
Block a user