Note that there are some explanatory texts on larger screens.

plurals
  1. POHow should I implement a Cayley Table in Haskell?
    primarykey
    data
    text
    <p>I'm interested in generalizing some computational tools to use a <a href="http://en.wikipedia.org/wiki/Cayley_table">Cayley Table</a>, meaning a lookup table based multiplication operation. </p> <p>I could create a minimal implementation as follows :</p> <pre><code>date CayleyTable = CayleyTable { ct_name :: ByteString, ct_products :: V.Vector (V.Vector Int) } deriving (Read, Show) instance Eq (CayleyTable) where (==) a b = ct_name a == ct_name b data CTElement = CTElement { ct_cayleytable :: CayleyTable, ct_index :: !Int } instance Eq (CTElement) where (==) a b = assert (ct_cayleytable a == ct_cayleytable b) $ ct_index a == ct_index b instance Show (CTElement) where show = ("CTElement" ++) . show . ctp_index a **** b = assert (ct_cayleytable a == ct_cayleytable b) $ ((ct_cayleytable a) ! a) ! b </code></pre> <p>There are however numerous problems with this approach, starting with the run time type checking via <code>ByteString</code> comparisons, but including the fact that <code>read</code> cannot be made to work correctly. Any idea how I should do this correctly?</p> <p>I could imagine creating a family of newtypes <code>CTElement1</code>, <code>CTElement2</code>, etc. for <code>Int</code> with a <code>CTElement</code> typeclass that provides the multiplication and verifies their type consistency, except when doing IO.</p> <p>Ideally, there might be some trick for passing around only one copy of this <code>ct_cayleytable</code> pointer too, perhaps using an implicit parameter like <code>?cayleytable</code>, but this doesn't play nicely with multiple incompatible Cayley tables and gets generally obnoxious. </p> <p>Also, I've gathered that an index into a vector can be viewed as a comonad. Is there any nice comonad instance for vector or whatever that might help smooth out this sort of type checking, even if ultimately doing it at runtime? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload