Representing Field Families #6

alanz opened this Issue Aug 16, 2011 · 3 comments


None yet

2 participants

alanz commented Aug 16, 2011

Another question. According to the Telehash protocol spec (, there can be multiple field in a given json message which are distinguished by a leading '+' character, followed by alpha-numerics. e.g. fields with names like "+end", or "+foo".

Without enumerating all possibilities, is there any way to gather these into a list or other structure in the underlying type?


data TeleHashEntry = TeleHashEntry 
                     { teleRing :: Int
                     , teleSee  :: Maybe [T.Text]
                     , teleBr   :: Int
                     , teleTo   :: T.Text
                     , teleLine :: Maybe T.Text
                     , teleHop  :: Maybe T.Text
                     , teleSignals::[ (T.Text,T.Text)] 
                     } deriving (Eq, Show)

telexJson = $(deriveIsos ''TeleHashEntry)

instance Json TeleHashEntry where
  grammar = telexJson . object
    ( prop "_ring"
    . prop ".see"
    . prop "_br"
    . prop "_to"
    . optionalProp "_line"
    . optionalProp "_hop"
    . prop "+????"      -- What should go here?

optionalProp :: Json a => String -> Iso (Object :- t) (Object :- Maybe a :- t)
optionalProp name = duck just . prop name <> duck nothing



Currently the closest you can get to this using the standard combinators is using rest which puts all the unprocessed properties on the stack as a map. When I've finished error reporting I'll give this some more thought. Perhaps a function like prop but with type Json a => (String -> Bool) -> Iso (Object :- t) (Object :- a :- t) would already be good enough for this.

alanz commented Aug 17, 2011

I think getting all the unprocessed properties in a map will be fine for me, and gives me a convenient check that I am not missing anything.



Alright. :-) Closing this issue then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment