From 94522d99adf0226458b823d4fb74faeb043265b8 Mon Sep 17 00:00:00 2001
From: Duncan Coutts <duncan@haskell.org>
Date: Fri, 21 Mar 2008 05:38:11 +0000
Subject: [PATCH] Add Text instance for License Initially it's exactly the same
 format as Read/Show. We can make it more liberal later.

---
 Distribution/InstalledPackageInfo.hs     | 2 +-
 Distribution/License.hs                  | 7 +++++++
 Distribution/PackageDescription/Parse.hs | 2 +-
 Distribution/ParseUtils.hs               | 2 +-
 4 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/Distribution/InstalledPackageInfo.hs b/Distribution/InstalledPackageInfo.hs
index 2274ac5e01..83d2e1b398 100644
--- a/Distribution/InstalledPackageInfo.hs
+++ b/Distribution/InstalledPackageInfo.hs
@@ -205,7 +205,7 @@ basicFieldDescrs =
                            disp                   parseOptVersion
                            packageVersion         (\ver pkg -> pkg{package=(package pkg){pkgVersion=ver}})
  , simpleField "license"
-                           (text . show)          parseLicenseQ
+                           disp                   parseLicenseQ
                            license                (\l pkg -> pkg{license=l})
  , simpleField "copyright"
                            showFreeText           parseFreeText
diff --git a/Distribution/License.hs b/Distribution/License.hs
index 10a9bd2f08..8966678adc 100644
--- a/Distribution/License.hs
+++ b/Distribution/License.hs
@@ -49,6 +49,10 @@ module Distribution.License (
 	License(..)
   ) where
 
+import Distribution.Text (Text(..))
+import qualified Distribution.Compat.ReadP as Parse
+import qualified Text.PrettyPrint as Disp
+
 -- |This datatype indicates the license under which your package is
 -- released.  It is also wise to add your license to each source file
 -- using the license-file field.  The 'AllRightsReserved' constructor
@@ -90,3 +94,6 @@ data License =
   | OtherLicense
   deriving (Read, Show, Eq)
 
+instance Text License where
+  disp  = Disp.text . show
+  parse = Parse.readS_to_P reads
diff --git a/Distribution/PackageDescription/Parse.hs b/Distribution/PackageDescription/Parse.hs
index c8c48b704d..8a67c4fb83 100644
--- a/Distribution/PackageDescription/Parse.hs
+++ b/Distribution/PackageDescription/Parse.hs
@@ -101,7 +101,7 @@ pkgDescrFieldDescrs =
            (text . maybe "" show) (fmap Just parseReadSQ)
            buildType              (\t pkg -> pkg{buildType=t})
  , simpleField "license"
-           (text . show)          parseLicenseQ
+           disp                   parseLicenseQ
            license                (\l pkg -> pkg{license=l})
  , simpleField "license-file"
            showFilePath           parseFilePathQ
diff --git a/Distribution/ParseUtils.hs b/Distribution/ParseUtils.hs
index 4a339e557c..cb91783093 100644
--- a/Distribution/ParseUtils.hs
+++ b/Distribution/ParseUtils.hs
@@ -555,7 +555,7 @@ parseTestedWithQ = parseQuoted tw <++ tw
 		return (compiler,version)
 
 parseLicenseQ :: ReadP r License
-parseLicenseQ = parseQuoted parseReadS <++ parseReadS
+parseLicenseQ = parseQuoted parse <++ parse
 
 -- urgh, we can't define optQuotes :: ReadP r a -> ReadP r a
 -- because the "compat" version of ReadP isn't quite powerful enough.  In
-- 
GitLab