Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6597087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:09:48+00:00 2026-05-25T18:09:48+00:00

I’m looking for a solution to interchange data between Haskell and Java/Scala/C# code. Currently,

  • 0

I’m looking for a solution to interchange data between Haskell and Java/Scala/C# code. Currently, I’m thinking about using XML. Ideally, I’d like the XML schema to be generated from my Haskell datatypes. My first try was HaXml 1.22.2, DrIFT 2.2.2. All on GHC 7.0.3. There is the following snippet:

import Data.List (isPrefixOf)
import Text.XML.HaXml.XmlContent
import Text.XML.HaXml.Types
import Text.XML.HaXml.Pretty (document)

data MyType = A | B String deriving (Eq, Show)
      {-! derive : XmlContent !-}   -- this line is for DrIFT

out of this file, DrIFT produces:

{- Generated by DrIFT (Automatic class derivations for Haskell) -}
{-# LINE 1 "ts.hs" #-}
import Data.List (isPrefixOf)
import Text.XML.HaXml.XmlContent
import Text.XML.HaXml.Types
import Text.XML.HaXml.Pretty (document)


data MyType = A | B String deriving (Eq, Show)
      {-! derive : XmlContent !-}   -- this line is for DrIFT
{-* Generated by DrIFT : Look, but Don't Touch. *-}
instance HTypeable MyType where
    toHType v =
    Defined "MyType" [] [Constr "A" [] [],Constr "B" [] [toHType aa]]
      where
    (B aa) = v
instance XmlContent MyType where
    parseContents = do
    { e@(Elem t _ _) <- elementWith (flip isPrefixOf) ["B","A"]
    ; case t of
      _ | "B" `isPrefixOf` t -> interior e $ fmap B parseContents
        | "A" `isPrefixOf` t -> interior e $ return A
    }
    toContents v@A =
    [mkElemC (showConstr 0 (toHType v)) []]
    toContents v@(B aa) =
    [mkElemC (showConstr 1 (toHType v)) (toContents aa)]

--  Imported from other files :-

Compiling this code with GHC produces an error message:

19:32:
    Couldn't match expected type `[Char]' with actual type `QName'
    In the second argument of `isPrefixOf', namely `t'
    In the expression: "B" `isPrefixOf` t
    In a stmt of a pattern guard for
                 a case alternative:
          "B" `isPrefixOf` t

Is it a problem with tooling or I’m doing something wrong? How to resolve this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:09:49+00:00Added an answer on May 25, 2026 at 6:09 pm

    Diggin around in the Hackage documentation for older versions of HaXml reveals that in version 1.20.2 and earlier, the Elem data constructor used to take a Name, which is just a type synonym for String. Sometime between that and version 1.22.3, however, it was changed to take a QName, which is a custom data type.

    It therefore makes sense that using isPrefixOf on element names would be valid for older versions, but invalid for newer versions.

    From the upload dates of these versions, this happened sometime during the last year, while DrIFT does not appear to have been updated since 2009.

    You should probably notify the DrIFT maintainer of this. In the meanwhile, you can work around it by using an older version of HaXml, or by writing the instances yourself. You should be able to use the incorrect generated instances as a starting point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.