I have a list of country id and country text in json
{
1 : "country one",
2 : "country two"
}
I have created below code to represent country id and text in haskell
data Country a = Country a
country1 :: Country String -- Representing country name
country1 = Country "country one"
country2 :: Country Integer -- Representing country id
country2 = Country 2
Above code is working fine. But I want to put constraint of a to take only values of String and Integer.
For that I tried below code . However, it is not working.
{-# LANGUAGE GADTs #-}
data Country a where
Country :: (String, Integer) => a -> Country a
toId :: Country String -> Country Integer
toId Country a = Country 1
toText :: Country Integer -> Country String
toText Country a = Country "country one"
Can anyone help to figure out how I can implement the above code in best way so that it is working ?