1
1
mirror of https://github.com/github/semantic.git synced 2024-12-21 13:51:44 +03:00

Define a function to construct singleton tables.

This commit is contained in:
Rob Rix 2017-08-31 22:40:50 -04:00
parent a827e8d331
commit 90b0475b1a

View File

@ -1,5 +1,6 @@
module Data.Syntax.Assignment.Table.Array
( Table(tableAddresses)
, tableSingleton
) where
import Data.Array
@ -9,6 +10,9 @@ import Data.Functor.Classes
data Table i a = Table { tableAddresses :: [i], tableBranches :: Array i (Maybe a) }
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
liftShowsPrec spA slA d Table{..} = showsBinaryWith showsPrec (const (liftShowList spA slA)) "Table" d tableAddresses (tableAddresses >>= \ addr -> (,) addr <$> toList (tableBranches ! addr))