-- TODO: we are checking for name clashes again here. Where is the best place
-- to do this check?
checkTyCon :: DataDecl -> Checker ()
checkTyCon d@(DataDecl sp name tyVars kindAnn ds)
  = lookup name <$> gets typeConstructors >>= \case
    Just _ -> throw TypeConstructorNameClash{ errLoc = sp, errId = name }
    Nothing -> modify' $ \st ->
      st{ typeConstructors = (name, (tyConKind, cardin, isIndexedDataType d)) : typeConstructors st }
  where
    cardin = (Just . genericLength) ds -- the number of data constructors
    tyConKind = mkKind (map snd tyVars)
    mkKind [] = case kindAnn of Just k -> k; Nothing -> KType -- default to `Type`
    mkKind (v:vs) = KFun v (mkKind vs)
checkTyCon :: DataDecl -> Checker ()
checkTyCon d@(DataDecl sp name tyVars kindAnn ds)
  = lookup name <$> gets typeConstructors >>= \case
    Just _ -> throw TypeConstructorNameClash{ errLoc = sp, errId = name }
    Nothing -> modify' $ \st ->
      st{ typeConstructors = (name, (tyConKind, cardin, isIndexedDataType d)) : typeConstructors st }
  where
    cardin = (Just . genericLength) ds -- the number of data constructors
    tyConKind = mkKind (map snd tyVars)
    mkKind [] = case kindAnn of Just k -> k; Nothing -> KType -- default to `Type`
    mkKind (v:vs) = KFun v (mkKind vs)
checkTyCon d@(DataDecl sp name tyVars kindAnn ds)
  = lookup name <$> gets typeConstructors >>= \case
    Just _ -> throw TypeConstructorNameClash{ errLoc = sp, errId = name }
    Nothing -> modify' $ \st ->
      st{ typeConstructors = (name, (tyConKind, cardin, isIndexedDataType d)) : typeConstructors st }
  where
    cardin = (Just . genericLength) ds -- the number of data constructors
    tyConKind = mkKind (map snd tyVars)
    mkKind [] = case kindAnn of Just k -> k; Nothing -> KType -- default to `Type`
    mkKind (v:vs) = KFun v (mkKind vs)