Jivan
Jivan

Reputation: 23068

Sum type with HashMap

The following code triggers an error:

import           Data.HashMap.Strict (HashMap) -- from unordered-containers
import           Data.Text

data Value =
    VText Text
  | VList [Text]
  | VMap HashMap Text Text
  deriving Show

The compiler complains that:

Expecting two more arguments to ‘HashMap’
  Expected a type, but ‘HashMap’ has kind ‘* -> * -> *’
  In the type ‘HashMap’
  In the definition of data constructor ‘VMap’
  In the data declaration for ‘Value’typecheck

How can I create a sum type like Value where one of the constructors takes a HashMap Text Text?

Upvotes: 1

Views: 98

Answers (1)

jf_
jf_

Reputation: 3479

By using parenthesis to disambiguate parameters for HashMap in VMap:

data Value =
    VText Text
  | VList [Text]
  | VMap (HashMap Text Text)
  deriving Show

Upvotes: 4

Related Questions