Data.Dependent.Map examples
Asked Answered
H

1

7

Are there any examples anywhere of how to use the DMap type? The package documentation is very learned, and I know it if for reference only, but it is singularly unhelpful for one getting started. Google reveals nothing that I can see.

Hardfavored answered 18/5, 2017 at 6:23 Comment(4)
What problem are you trying to solve that you think DMap will help you with?Underestimate
I was thinking maybe it could be used to make a map where the values may have any different type depending on the type of key.Hardfavored
Well, there is one in the READMEDenizen
DMap is used very heavily in reflex, so you can take a look at that package.Clem
P
0

From the Updated README.md example pull request. One need to implement GEq and GCompare instances for a GADT:

data Foo a where
  AnInt   :: Foo Int
  AString :: Foo String

deriveGEq      ''Foo
deriveGCompare ''Foo

dmap1 :: DMap Foo Identity
dmap1 = fromList [AnInt ==> 1, AString ==> "bar"]

main = do
  print $ dmap1 ! AnInt
  print $ dmap1 ! AString
Pecos answered 13/6, 2018 at 0:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.