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

  • SEARCH
  • Home
  • 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 7848335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:09:56+00:00 2026-06-02T18:09:56+00:00

The encoding package uses HaXml in its build script (in Setup.hs ). It happens

  • 0

The encoding package uses HaXml in its build script (in Setup.hs). It happens to use bits of the interface that changed between HaXml-1.19 and HaXml-1.22. It would be nice if the encoding package were able to build with either version. I tried using the usual Cabal trick, namely, doing something like

{-# LANGUAGE CPP #-}
#if MIN_VERSION_HaXml(1,22,0)
-- HaXml-1.22 code
#else
-- HaXml-1.19 code
#endif

…but the magic defines can’t exist before the package is configured, and this file is being built to make the configure step possible. What are my options? Is there a way to change the command that cabal-install calls to compile Setup.hs? Is there another mechanism for conditionally selecting code that sidesteps cabal?

  • 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-06-02T18:09:58+00:00Added an answer on June 2, 2026 at 6:09 pm

    The Data.Data interface is capable (just about!) of constructing and deconstructing values of a type that may or may not exist. Unfortunately, HaXml doesn’t appear to have Data instances for its types, and you can’t define one since you can’t refer to the type that might or might not exist, so we have to resort to Template Haskell:

    The following module exports qnameCompat:

    {-# LANGUAGE TemplateHaskell #-}
    module HaXmlCompat (qnameCompat) where
    
    import Language.Haskell.TH
    
    qnameCompat :: Q [Dec]
    qnameCompat = do
      mi <- maybeReify "N"
      case mi of
        Nothing -> sequence [
          tySynD (mkName "QName") [] [t| String |],
          valD [p| toQName |] (normalB [| id |]) [],
          valD [p| fromQName |] (normalB [| Just |]) []]
        Just (DataConI n _ _ _) -> do
          s <- newName "s"
          sequence [
            valD [p| toQName |] (normalB (conE n)) [],
            funD (mkName "fromQName") [
              clause [conP n [varP s]] (normalB (appE [| Just |] (varE s))) [],
              clause [ [p| _ |] ] (normalB [| Nothing |]) []]]
        Just i -> fail $
          "N exists, but isn't the sort of thing I expected: " ++ show i
    
    maybeReify :: String -> Q (Maybe Info)
    maybeReify = recover (return Nothing) . fmap Just . reify . mkName
    

    When spliced at the top level using Template Haskell, qnameCompat will check if N exists. If it does, it produces the following code:

    toQName = N
    fromQName (N s) = Just s
    fromQName _ = Nothing
    

    If it doesn’t, the following is produced:

    type QName = String
    toQName = id
    fromQName = Just
    

    Now you can create and deconstruct Elements, e.g. using the ViewPatterns extension:

    myElt :: String -> Element i
    myElt = Elem (toQName "elemName") [] []
    
    eltName :: Element i -> String
    eltName (Elem (fromQName -> Just n) _ _) = n
    

    ViewPatterns is convenient, but not essential, of course: using ordinary pattern matching on the result of fromQName will work just as well.

    (These ideas are what led me to develop the notcpp package, which includes maybeReify and some other useful utilities)

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

Sidebar

Related Questions

Currently, I am testing a ruby script that uses mechanize with ruby 1.9.2 (Ubuntu
When using the MnSymbol package, pdflatex gives two font warnings: LaTeX Font Warning: Encoding
What encoding we need to use to save a file as text file(of type
What kind of encoding do you use to encode http:// as http%253A%252F%252F HttpUtility.UrlEncode gives
I have a list that uses a itemRendererFunction to get custom item renderers. Is
I am building an Android app that uses wifi. I have properly declared these
I have the following class that extends AdvancedDataGridItemRenderer: package { import mx.controls.advancedDataGridClasses.AdvancedDataGridItemRenderer; public class
I have an IRC bot written in python that uses Twisted. It can print
I have a web application that uses spring and hibernate for JPA support, but
I have a maven project that uses some custom jars [not found in any

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.