[Haskell-cafe] Key-Parametrized Lookup Table

Alp Mestanogullari alpmestan at gmail.com
Tue Jul 31 14:47:49 CEST 2012


Would ixset or HiggsSet be suitable?

http://hackage.haskell.org/package/ixset<http://hackage.haskell.org/package/ixset-1.0.5>
http://hackage.haskell.org/package/HiggsSet

On Tue, Jul 31, 2012 at 12:56 PM, Alexander Foremny <
alexanderforemny at gmail.com> wrote:

> At first glance I noticed some problems with the vault library for my
> particular approach.
>
> Despite from being unique, Key values don't appear to carry any
> information like the Label I need. However, it might be possible to
> work around that.
>
> The more grave problem seems to be that a Key cannot be
> (de-)serialized. This might be impossible due to the type parameter a
> in Key a.
> However, it is no problem to fix the types of values to some finite
> collection.
>
> Because of this some solution built around Dynamic seems to be more
> and more appropriate. But I'll try to investigate vault further.
>
> Regards,
> Alexander Foremny
>
> 2012/7/31 Alexander Foremny <alexanderforemny at gmail.com>:
> > Dear Michael,
> >
> > thank you very much for your quick and interesting response. This
> > looks very much like what I want!
> >
> > Regards,
> > Alexander Foremny
> >
> > 2012/7/31 Michael Snoyman <michael at snoyman.com>:
> >> On Tue, Jul 31, 2012 at 1:13 PM, Alexander Foremny
> >> <alexanderforemny at gmail.com> wrote:
> >>> Hello list,
> >>>
> >>> I am currently thinking that a problem of mine would best be solved if
> >>> there was a Map-like data structure in which the value returned is
> >>> parametrized over the lookup type.
> >>>
> >>> I wonder is this makes sense and if such a data structure exists or if
> >>> it could be created while still being well typed. I essentially want
> >>> to statically define a scope of Key values and dynamically define a
> >>> list of keys.
> >>>
> >>>> -- Scope of possible keys.
> >>>> type Label = String
> >>>> data Key a where
> >>>>     KeyStr :: Label -> Key String
> >>>>     KeyInt :: Label -> Key Int
> >>>>     KeyChoice :: Label -> [a] -> Key a
> >>>
> >>>> -- Some key values, to be extended at runtime.
> >>>> strKey "Some String"
> >>>> strKey' "Another String"
> >>>> intKey "Some integer"
> >>>> choiceKey "Chose one" [ "a", "b", "c" ] :: KeyChoice String
> >>>
> >>> Now I need a data structure to possibly associate a value to the key.
> >>>
> >>>> data MapG = ...
> >>>> type Value a = a
> >>>> insert :: Key a -> Value a -> MapG Key Value -> MapG Key Value
> >>>> lookup :: Key a -> MapG Key Value -> Maybe (Value a)
> >>>
> >>> I tried implementing this with multiple Map k a's. I tried adding a
> >>> phantom type on some storage type of to implement KeyChoice as of type
> >>> Key Int, but I ran into troubles with this approach. I wonder if
> >>> Dynamic or Type Families could achieve this, but I am quite at a loss
> >>> and would like to hear your opinion.
> >>>
> >>> I did try to search for this a bit, but I don't quite know how to
> >>> phrase my problem. I'd like to apologize in advance if this question
> >>> has been asked already.
> >>>
> >>> Regards,
> >>> Alexander Foremny
> >>>
> >>> _______________________________________________
> >>> Haskell-Cafe mailing list
> >>> Haskell-Cafe at haskell.org
> >>> http://www.haskell.org/mailman/listinfo/haskell-cafe
> >>
> >> I think you might be looking for something like vault[1].
> >>
> >> HTH,
> >> Michael
> >>
> >> [1] http://hackage.haskell.org/package/vault
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



-- 
Alp Mestanogullari
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120731/d6c9daaa/attachment.htm>


More information about the Haskell-Cafe mailing list