1
+ {-# LANGUAGE CPP #-}
1
2
{-# LANGUAGE DeriveTraversable #-}
2
3
{-# LANGUAGE FlexibleContexts #-}
3
4
{-# LANGUAGE OverloadedStrings #-}
@@ -60,7 +61,7 @@ import qualified Numeric.Natural
60
61
import qualified Prettyprinter.Render.String as Pretty
61
62
import qualified System.IO
62
63
63
-
64
+
64
65
{-| This fully resolves, type checks, and normalizes the expression, so the
65
66
resulting AST is self-contained.
66
67
@@ -160,9 +161,9 @@ toNestedHaskellType typeParams haskellTypes = loop
160
161
, " \n "
161
162
, " ... which did not fit any of the above criteria."
162
163
]
163
-
164
+
164
165
message dhallType = Pretty. renderString (Dhall.Pretty. layout (document dhallType))
165
-
166
+
166
167
loop dhallType = case dhallType of
167
168
Bool ->
168
169
return (ConT ''Bool)
@@ -203,7 +204,7 @@ toNestedHaskellType typeParams haskellTypes = loop
203
204
haskellElementType <- loop dhallElementType
204
205
205
206
return (AppT haskellAppType haskellElementType)
206
-
207
+
207
208
Var v
208
209
| Just (V param index) <- List. find (v == ) typeParams -> do
209
210
let name = Syntax. mkName $ (Text. unpack param) ++ (show index)
@@ -255,15 +256,21 @@ toDeclaration generateOptions@GenerateOptions{..} haskellTypes typ =
255
256
MultipleConstructors {.. } -> uncurry (fromMulti typeName) $ getTypeParams code
256
257
where
257
258
getTypeParams = first numberConsecutive . getTypeParams_ []
258
-
259
+
259
260
getTypeParams_ acc (Lam _ (FunctionBinding _ v _ _ _) rest) = getTypeParams_ (v: acc) rest
260
261
getTypeParams_ acc rest = (acc, rest)
261
262
262
263
derivingClauses = [ derivingGenericClause | generateFromDhallInstance || generateToDhallInstance ]
263
264
264
265
interpretOptions = generateToInterpretOptions generateOptions typ
265
266
266
- toTypeVar (V n i) = Syntax. PlainTV $ Syntax. mkName (Text. unpack n ++ show i)
267
+ #if MIN_VERSION_template_haskell(2,17,0)
268
+ toTypeVar :: Var -> Syntax. TyVarBndr ()
269
+ toTypeVar (V n i) = Syntax. PlainTV (Syntax. mkName (Text. unpack n ++ show i)) ()
270
+ #else
271
+ toTypeVar :: Var -> Syntax. TyVarBndr
272
+ toTypeVar (V n i) = Syntax. PlainTV (Syntax. mkName (Text. unpack n ++ show i))
273
+ #endif
267
274
268
275
toDataD typeName typeParams constructors = do
269
276
let name = Syntax. mkName (Text. unpack typeName)
@@ -277,16 +284,16 @@ toDeclaration generateOptions@GenerateOptions{..} haskellTypes typ =
277
284
278
285
fromSingle typeName constructorName typeParams dhallType = do
279
286
constructor <- toConstructor typeParams generateOptions haskellTypes typeName (constructorName, Just dhallType)
280
-
287
+
281
288
toDataD typeName typeParams [constructor]
282
-
289
+
283
290
fromMulti typeName typeParams dhallType = case dhallType of
284
291
Union kts -> do
285
292
constructors <- traverse (toConstructor typeParams generateOptions haskellTypes typeName) (Dhall.Map. toList kts)
286
293
287
294
toDataD typeName typeParams constructors
288
-
289
- _ -> fail $ message dhallType
295
+
296
+ _ -> fail $ message dhallType
290
297
291
298
message dhallType = Pretty. renderString (Dhall.Pretty. layout $ document dhallType)
292
299
0 commit comments