namespaced :: ToJSON a
           => NS
           -> Template
           -> Either Error a
           -> DirTree (Either Error Rendered)
namespaced (unNS -> ns) t x =
    case map fromText ns of
        []  -> error "Empty namespace."
        [p] -> f p
        ps  -> foldr' nest (f (last ps)) (init ps)
  where
    f p = file' (p <.> "hs") t x

    nest d c = Dir (encodeString d) [c]
namespaced :: ToJSON a
           => NS
           -> Template
           -> Either Error a
           -> DirTree (Either Error Rendered)
namespaced (unNS -> ns) t x =
    case map fromText ns of
        []  -> error "Empty namespace."
        [p] -> f p
        ps  -> foldr' nest (f (last ps)) (init ps)
  where
    f p = file' (p <.> "hs") t x

    nest d c = Dir (encodeString d) [c]
namespaced (unNS -> ns) t x =
    case map fromText ns of
        []  -> error "Empty namespace."
        [p] -> f p
        ps  -> foldr' nest (f (last ps)) (init ps)
  where
    f p = file' (p <.> "hs") t x

    nest d c = Dir (encodeString d) [c]