GADTs in the wild
Scott Michel
scooter.phd at gmail.com
Thu Aug 23 20:47:06 CEST 2012
Here's an example (not a complete module) I was using to represent
bit-oriented structures as they occur in certain space applications,
notably GPS frames. "Fixed" allows for fixed-sized fields and lets the end
user choose the integral type that's best for the structure.
At least it's not a parser or language example. :-)
-scooter
-- | Member fields, etc., that comprise a 'BitStruct'
data Member where
Field :: String -- Field name
-> Int -- Field length
-> Bool -- Signed (True) or unsigned (False)
-> Member
ZeroPad :: String -- Field name
-> Int -- Field length
-> Member
OnesPad :: String -- Field name
-> Int -- Field length
-> Member
ArbPad :: String -- Field name
-> Int -- Field length
-> Member
Reserved :: String -- Field name
-> Int -- Field length
-> Member
Fixed :: (Integral x, Show x) =>
String -- Field name
-> Int -- Field length
-> Bool -- Signed (True) or unsigned (False)
-> x -- Type of the fixed field's value
-> Member
Variant :: (Integral x, Show x) =>
String -- Variant prefix name
-> Maybe BitStruct -- Header before the tag
-> TagElement -- The tag element itself
-> Maybe BitStruct -- Common elements after the tag
-> Seq (x, BitStruct) -- Variant element tuples (value,
structure)
-> Member
-- Mult-value variant: Use this when multiple variant tag values have the
-- same structure:
MultiValueVariant :: (Integral x, Show x) =>
String -- Variant prefix name
-> Maybe BitStruct -- Header before the tag
-> TagElement -- The tag element itself
-> Maybe BitStruct -- Common elements after
the tag
-> Seq ([x], BitStruct) -- Variant element tuples
([values], structure)
-> Member
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20120823/cdf72524/attachment.htm>
More information about the Glasgow-haskell-users
mailing list