-- This file is part of Hoppy.
--
-- Copyright 2015-2021 Bryan Gardiner <bog@khumba.net>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
--     http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

{-# LANGUAGE CPP #-}

-- | Bindings for @std::set@.
module Foreign.Hoppy.Generator.Std.Set (
  Options (..),
  defaultOptions,
  Contents (..),
  instantiate,
  instantiate',
  toExports,
  ) where

import Control.Monad (when)
#if !MIN_VERSION_base(4,8,0)
import Data.Monoid (mconcat)
#endif
import Foreign.Hoppy.Generator.Language.Haskell (
  HsTypeSide (HsHsSide),
  addImports,
  cppTypeToHsTypeAndUse,
  indent,
  ln,
  prettyPrint,
  sayLn,
  saysLn,
  )
import Foreign.Hoppy.Generator.Spec (
  Constness (Const, Nonconst),
  Export (Export),
  Operator (OpEq),
  Purity (Nonpure),
  Reqs,
  Type,
  addAddendumHaskell,
  addReqs,
  hsImport1,
  hsImportForPrelude,
  hsImportForRuntime,
  ident1T,
  ident2,
  identT',
  includeStd,
  np,
  reqInclude,
  toExtName,
  )
import Foreign.Hoppy.Generator.Spec.Class (
  Class,
  MethodApplicability (MNormal),
  makeClass,
  makeFnMethod,
  mkConstMethod,
  mkConstMethod',
  mkCtor,
  mkMethod,
  mkMethod',
  toHsCastMethodName,
  toHsDataTypeName,
  toHsClassEntityName,
  )
import Foreign.Hoppy.Generator.Spec.ClassFeature (
  ClassFeature (Assignable, Comparable, Copyable),
  classAddFeatures,
  )
import Foreign.Hoppy.Generator.Std (ValueConversion (ConvertPtr, ConvertValue))
import Foreign.Hoppy.Generator.Std.Internal (includeHelper)
import Foreign.Hoppy.Generator.Std.Iterator
import Foreign.Hoppy.Generator.Types

-- | Options for instantiating the set classes.
data Options = Options
  { Options -> [ClassFeature]
optSetClassFeatures :: [ClassFeature]
    -- ^ Additional features to add to the @std::set@ class.  Sets are always
    -- 'Assignable', 'Comparable', and 'Copyable', but you may want to add
    -- 'Foreign.Hoppy.Generator.Spec.ClassFeature.Equatable' if your value type
    -- supports those.
  , Options -> Maybe ValueConversion
optValueConversion :: Maybe ValueConversion
  }

-- | The default options have no additional 'ClassFeature's.
defaultOptions :: Options
defaultOptions :: Options
defaultOptions = [ClassFeature] -> Maybe ValueConversion -> Options
Options [] Maybe ValueConversion
forall a. Maybe a
Nothing

-- | A set of instantiated set classes.
data Contents = Contents
  { Contents -> Class
c_set :: Class  -- ^ @std::set\<T>@
  , Contents -> Class
c_iterator :: Class  -- ^ @std::set\<T>::iterator@
  , Contents -> Class
c_constIterator :: Class  -- ^ @std::set\<T>::const_iterator@
  }

-- | @instantiate className t tReqs@ creates a set of bindings for an
-- instantiation of @std::set@ and associated types (e.g. iterators).  In the
-- result, the 'c_set' class has an external name of @className@, and the
-- iterator class is further suffixed with @\"Iterator\"@.
instantiate :: String -> Type -> Reqs -> Contents
instantiate :: String -> Type -> Reqs -> Contents
instantiate String
setName Type
t Reqs
tReqs = String -> Type -> Reqs -> Options -> Contents
instantiate' String
setName Type
t Reqs
tReqs Options
defaultOptions

-- | 'instantiate' with additional options.
instantiate' :: String -> Type -> Reqs -> Options -> Contents
instantiate' :: String -> Type -> Reqs -> Options -> Contents
instantiate' String
setName Type
t Reqs
tReqs Options
opts =
  let reqs :: Reqs
reqs = [Reqs] -> Reqs
forall a. Monoid a => [a] -> a
mconcat
             [ Reqs
tReqs
             , Include -> Reqs
reqInclude (Include -> Reqs) -> Include -> Reqs
forall a b. (a -> b) -> a -> b
$ String -> Include
includeHelper String
"set.hpp"
             , Include -> Reqs
reqInclude (Include -> Reqs) -> Include -> Reqs
forall a b. (a -> b) -> a -> b
$ String -> Include
includeStd String
"set"
             ]
      iteratorName :: String
iteratorName = String
setName String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"Iterator"

      set :: Class
set =
        (case Options -> Maybe ValueConversion
optValueConversion Options
opts of
           Maybe ValueConversion
Nothing -> Class -> Class
forall a. a -> a
id
           Just ValueConversion
conversion -> Generator () -> Class -> Class
forall a. HasAddendum a => Generator () -> a -> a
addAddendumHaskell (Generator () -> Class -> Class) -> Generator () -> Class -> Class
forall a b. (a -> b) -> a -> b
$ ValueConversion -> Generator ()
makeAddendum ValueConversion
conversion) (Class -> Class) -> Class -> Class
forall a b. (a -> b) -> a -> b
$
        Reqs -> Class -> Class
forall a. HasReqs a => Reqs -> a -> a
addReqs Reqs
reqs (Class -> Class) -> Class -> Class
forall a b. (a -> b) -> a -> b
$
        [ClassFeature] -> Class -> Class
classAddFeatures (ClassFeature
Assignable ClassFeature -> [ClassFeature] -> [ClassFeature]
forall a. a -> [a] -> [a]
: ClassFeature
Comparable ClassFeature -> [ClassFeature] -> [ClassFeature]
forall a. a -> [a] -> [a]
: ClassFeature
Copyable ClassFeature -> [ClassFeature] -> [ClassFeature]
forall a. a -> [a] -> [a]
: Options -> [ClassFeature]
optSetClassFeatures Options
opts) (Class -> Class) -> Class -> Class
forall a b. (a -> b) -> a -> b
$
        Identifier -> Maybe ExtName -> [Class] -> [ClassEntity] -> Class
makeClass (String -> String -> [Type] -> Identifier
ident1T String
"std" String
"set" [Type
t]) (ExtName -> Maybe ExtName
forall a. a -> Maybe a
Just (ExtName -> Maybe ExtName) -> ExtName -> Maybe ExtName
forall a b. (a -> b) -> a -> b
$ HasCallStack => String -> ExtName
String -> ExtName
toExtName String
setName) []
        [ String -> [Parameter] -> ClassEntity
forall p. IsParameter p => String -> [p] -> ClassEntity
mkCtor String
"new" [Parameter]
np
        , String -> String -> [Parameter] -> Type -> ClassEntity
forall name p.
(IsFnName String name, IsParameter p) =>
name -> String -> [p] -> Type -> ClassEntity
mkMethod' String
"begin" String
"begin" [Parameter]
np (Type -> ClassEntity) -> Type -> ClassEntity
forall a b. (a -> b) -> a -> b
$ Type -> Type
toGcT (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Class -> Type
objT Class
iterator
        , String -> String -> [Parameter] -> Type -> ClassEntity
forall name p.
(IsFnName String name, IsParameter p) =>
name -> String -> [p] -> Type -> ClassEntity
mkConstMethod' String
"begin" String
"beginConst" [Parameter]
np (Type -> ClassEntity) -> Type -> ClassEntity
forall a b. (a -> b) -> a -> b
$ Type -> Type
toGcT (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Class -> Type
objT Class
constIterator
        , String -> [Parameter] -> Type -> ClassEntity
forall name p.
(IsFnName String name, IsParameter p) =>
name -> [p] -> Type -> ClassEntity
mkMethod String
"clear" [Parameter]
np Type
voidT
        , String -> [Type] -> Type -> ClassEntity
forall name p.
(IsFnName String name, IsParameter p) =>
name -> [p] -> Type -> ClassEntity
mkConstMethod String
"count" [Type
t] Type
sizeT
          -- TODO count
        , String -> [Parameter] -> Type -> ClassEntity
forall name p.
(IsFnName String name, IsParameter p) =>
name -> [p] -> Type -> ClassEntity
mkConstMethod String
"empty" [Parameter]
np Type
boolT
        , String -> String -> [Parameter] -> Type -> ClassEntity
forall name p.
(IsFnName String name, IsParameter p) =>
name -> String -> [p] -> Type -> ClassEntity
mkMethod' String
"end" String
"end" [Parameter]
np (Type -> ClassEntity) -> Type -> ClassEntity
forall a b. (a -> b) -> a -> b
$ Type -> Type
toGcT (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Class -> Type
objT Class
iterator
        , String -> String -> [Parameter] -> Type -> ClassEntity
forall name p.
(IsFnName String name, IsParameter p) =>
name -> String -> [p] -> Type -> ClassEntity
mkConstMethod' String
"end" String
"endConst" [Parameter]
np (Type -> ClassEntity) -> Type -> ClassEntity
forall a b. (a -> b) -> a -> b
$ Type -> Type
toGcT (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Class -> Type
objT Class
constIterator
          -- equalRange: find is good enough.
        , String -> String -> [Type] -> Type -> ClassEntity
forall name p.
(IsFnName String name, IsParameter p) =>
name -> String -> [p] -> Type -> ClassEntity
mkMethod' String
"erase" String
"erase" [Class -> Type
objT Class
iterator] Type
voidT
        , String -> String -> [Type] -> Type -> ClassEntity
forall name p.
(IsFnName String name, IsParameter p) =>
name -> String -> [p] -> Type -> ClassEntity
mkMethod' String
"erase" String
"eraseRange" [Class -> Type
objT Class
iterator, Class -> Type
objT Class
iterator] Type
voidT
        , String -> [Type] -> Type -> ClassEntity
forall name p.
(IsFnName String name, IsParameter p) =>
name -> [p] -> Type -> ClassEntity
mkMethod String
"find" [Type
t] (Type -> ClassEntity) -> Type -> ClassEntity
forall a b. (a -> b) -> a -> b
$ Type -> Type
toGcT (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Class -> Type
objT Class
iterator
          -- TODO Replace these with a single version that returns a (toGcT std::pair).
        , Identifier
-> String
-> MethodApplicability
-> Purity
-> [Type]
-> Type
-> ClassEntity
forall name p.
(IsFnName Identifier name, IsParameter p) =>
name
-> String
-> MethodApplicability
-> Purity
-> [p]
-> Type
-> ClassEntity
makeFnMethod (String -> String -> String -> Identifier
ident2 String
"hoppy" String
"set" String
"insert") String
"insert"
          MethodApplicability
MNormal Purity
Nonpure [Type -> Type
refT (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Class -> Type
objT Class
set, Type
t] Type
boolT
        , Identifier
-> String
-> MethodApplicability
-> Purity
-> [Type]
-> Type
-> ClassEntity
forall name p.
(IsFnName Identifier name, IsParameter p) =>
name
-> String
-> MethodApplicability
-> Purity
-> [p]
-> Type
-> ClassEntity
makeFnMethod (String -> String -> String -> Identifier
ident2 String
"hoppy" String
"set" String
"insertAndGetIterator") String
"insertAndGetIterator"
          MethodApplicability
MNormal Purity
Nonpure [Type -> Type
refT (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Class -> Type
objT Class
set, Type
t] (Type -> ClassEntity) -> Type -> ClassEntity
forall a b. (a -> b) -> a -> b
$ Type -> Type
toGcT (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Class -> Type
objT Class
iterator
          -- lower_bound: find is good enough.
        , String -> String -> [Parameter] -> Type -> ClassEntity
forall name p.
(IsFnName String name, IsParameter p) =>
name -> String -> [p] -> Type -> ClassEntity
mkConstMethod' String
"max_size" String
"maxSize" [Parameter]
np Type
sizeT
        , String -> [Parameter] -> Type -> ClassEntity
forall name p.
(IsFnName String name, IsParameter p) =>
name -> [p] -> Type -> ClassEntity
mkConstMethod String
"size" [Parameter]
np Type
sizeT
        , String -> [Type] -> Type -> ClassEntity
forall name p.
(IsFnName String name, IsParameter p) =>
name -> [p] -> Type -> ClassEntity
mkMethod String
"swap" [Type -> Type
refT (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Class -> Type
objT Class
set] Type
voidT
          -- upper_bound: find is good enough.
        ]

      -- Set iterators are always constant, because modifying elements in place
      -- will break the internal order of the set.  That said, 'iterator' and
      -- 'const_iterator' aren't guaranteed to be the same type; only that
      -- 'iterator' is convertible to 'const_iterator'.
      iterator :: Class
iterator =
        Reqs -> Class -> Class
forall a. HasReqs a => Reqs -> a -> a
addReqs Reqs
reqs (Class -> Class) -> Class -> Class
forall a b. (a -> b) -> a -> b
$
        IteratorMutability -> Maybe Type -> Class -> Class
makeBidirectionalIterator IteratorMutability
Constant (Type -> Maybe Type
forall a. a -> Maybe a
Just Type
t) (Class -> Class) -> Class -> Class
forall a b. (a -> b) -> a -> b
$
        Identifier -> Maybe ExtName -> [Class] -> [ClassEntity] -> Class
makeClass ([(String, Maybe [Type])] -> Identifier
identT' [(String
"std", Maybe [Type]
forall a. Maybe a
Nothing), (String
"set", [Type] -> Maybe [Type]
forall a. a -> Maybe a
Just [Type
t]), (String
"iterator", Maybe [Type]
forall a. Maybe a
Nothing)])
        (ExtName -> Maybe ExtName
forall a. a -> Maybe a
Just (ExtName -> Maybe ExtName) -> ExtName -> Maybe ExtName
forall a b. (a -> b) -> a -> b
$ HasCallStack => String -> ExtName
String -> ExtName
toExtName String
iteratorName) [] []

      constIterator :: Class
constIterator =
        Reqs -> Class -> Class
forall a. HasReqs a => Reqs -> a -> a
addReqs Reqs
reqs (Class -> Class) -> Class -> Class
forall a b. (a -> b) -> a -> b
$
        IteratorMutability -> Maybe Type -> Class -> Class
makeBidirectionalIterator IteratorMutability
Constant (Type -> Maybe Type
forall a. a -> Maybe a
Just Type
t) (Class -> Class) -> Class -> Class
forall a b. (a -> b) -> a -> b
$
        Identifier -> Maybe ExtName -> [Class] -> [ClassEntity] -> Class
makeClass ([(String, Maybe [Type])] -> Identifier
identT' [(String
"std", Maybe [Type]
forall a. Maybe a
Nothing), (String
"set", [Type] -> Maybe [Type]
forall a. a -> Maybe a
Just [Type
t]), (String
"const_iterator", Maybe [Type]
forall a. Maybe a
Nothing)])
        (ExtName -> Maybe ExtName
forall a. a -> Maybe a
Just (ExtName -> Maybe ExtName) -> ExtName -> Maybe ExtName
forall a b. (a -> b) -> a -> b
$ HasCallStack => String -> ExtName
String -> ExtName
toExtName String
iteratorName) [] []

      -- The addendum for the set class contains HasContents and FromContents
      -- instances.
      makeAddendum :: ValueConversion -> Generator ()
makeAddendum ValueConversion
conversion = do
        HsImportSet -> Generator ()
addImports (HsImportSet -> Generator ()) -> HsImportSet -> Generator ()
forall a b. (a -> b) -> a -> b
$ [HsImportSet] -> HsImportSet
forall a. Monoid a => [a] -> a
mconcat [String -> String -> HsImportSet
hsImport1 String
"Prelude" String
"($)",
                              HsImportSet
hsImportForPrelude,
                              HsImportSet
hsImportForRuntime]
        Bool -> Generator () -> Generator ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (ValueConversion
conversion ValueConversion -> ValueConversion -> Bool
forall a. Eq a => a -> a -> Bool
== ValueConversion
ConvertValue) (Generator () -> Generator ()) -> Generator () -> Generator ()
forall a b. (a -> b) -> a -> b
$
          HsImportSet -> Generator ()
addImports (HsImportSet -> Generator ()) -> HsImportSet -> Generator ()
forall a b. (a -> b) -> a -> b
$ [HsImportSet] -> HsImportSet
forall a. Monoid a => [a] -> a
mconcat [String -> String -> HsImportSet
hsImport1 String
"Prelude" String
"(=<<)"]

        String
hsDataNameConst <- Constness -> Class -> Generator String
toHsDataTypeName Constness
Const Class
set
        String
hsDataName <- Constness -> Class -> Generator String
toHsDataTypeName Constness
Nonconst Class
set

        let computeValueType :: Constness -> Generator HsType
computeValueType Constness
cst =
              HsTypeSide -> Type -> Generator HsType
cppTypeToHsTypeAndUse HsTypeSide
HsHsSide (Type -> Generator HsType) -> Type -> Generator HsType
forall a b. (a -> b) -> a -> b
$
              (case ValueConversion
conversion of
                 ValueConversion
ConvertPtr -> Type -> Type
ptrT
                 ValueConversion
ConvertValue -> Type -> Type
forall a. a -> a
id) (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
              case Constness
cst of
                Constness
Const -> Type -> Type
constT Type
t
                Constness
Nonconst -> Type
t
        HsType
hsValueTypeConst <- Constness -> Generator HsType
computeValueType Constness
Const
        HsType
hsValueType <- Constness -> Generator HsType
computeValueType Constness
Nonconst

        String
setConstCast <- Constness -> Class -> Generator String
toHsCastMethodName Constness
Const Class
set
        String
setEmpty <- Class -> String -> Generator String
forall name.
IsFnName String name =>
Class -> name -> Generator String
toHsClassEntityName Class
set String
"empty"
        String
setBeginConst <- Class -> String -> Generator String
forall name.
IsFnName String name =>
Class -> name -> Generator String
toHsClassEntityName Class
set String
"beginConst"
        String
setEndConst <- Class -> String -> Generator String
forall name.
IsFnName String name =>
Class -> name -> Generator String
toHsClassEntityName Class
set String
"endConst"
        String
iterEq <- Class -> Operator -> Generator String
forall name.
IsFnName String name =>
Class -> name -> Generator String
toHsClassEntityName Class
iterator Operator
OpEq
        String
iterGetConst <- Class -> String -> Generator String
forall name.
IsFnName String name =>
Class -> name -> Generator String
toHsClassEntityName Class
iterator String
"getConst"
        String
iterPrev <- Class -> String -> Generator String
forall name.
IsFnName String name =>
Class -> name -> Generator String
toHsClassEntityName Class
iterator String
"prev"

        -- Generate const and nonconst HasContents instances.
        Generator ()
ln
        [String] -> Generator ()
saysLn [String
"instance HoppyFHR.HasContents ", String
hsDataNameConst,
                String
" (", HsType -> String
forall a. Pretty a => a -> String
prettyPrint HsType
hsValueTypeConst, String
") where"]
        Generator () -> Generator ()
forall a. Generator a -> Generator a
indent (Generator () -> Generator ()) -> Generator () -> Generator ()
forall a b. (a -> b) -> a -> b
$ do
          String -> Generator ()
sayLn String
"toContents this' = do"
          Generator () -> Generator ()
forall a. Generator a -> Generator a
indent (Generator () -> Generator ()) -> Generator () -> Generator ()
forall a b. (a -> b) -> a -> b
$ do
            [String] -> Generator ()
saysLn [String
"empty' <- ", String
setEmpty, String
" this'"]
            String -> Generator ()
sayLn String
"if empty' then HoppyP.return [] else do"
            Generator () -> Generator ()
forall a. Generator a -> Generator a
indent (Generator () -> Generator ()) -> Generator () -> Generator ()
forall a b. (a -> b) -> a -> b
$ do
              [String] -> Generator ()
saysLn [String
"begin' <- ", String
setBeginConst, String
" this'"]
              [String] -> Generator ()
saysLn [String
"iter' <- ", String
setEndConst, String
" this'"]
              String -> Generator ()
sayLn String
"go' iter' begin' []"
            String -> Generator ()
sayLn String
"where"
            Generator () -> Generator ()
forall a. Generator a -> Generator a
indent (Generator () -> Generator ()) -> Generator () -> Generator ()
forall a b. (a -> b) -> a -> b
$ do
              String -> Generator ()
sayLn String
"go' iter' begin' acc' = do"
              Generator () -> Generator ()
forall a. Generator a -> Generator a
indent (Generator () -> Generator ()) -> Generator () -> Generator ()
forall a b. (a -> b) -> a -> b
$ do
                [String] -> Generator ()
saysLn [String
"stop' <- ", String
iterEq, String
" iter' begin'"]
                String -> Generator ()
sayLn String
"if stop' then HoppyP.return acc' else do"
                Generator () -> Generator ()
forall a. Generator a -> Generator a
indent (Generator () -> Generator ()) -> Generator () -> Generator ()
forall a b. (a -> b) -> a -> b
$ do
                  [String] -> Generator ()
saysLn [String
"_ <- ", String
iterPrev, String
" iter'"]
                  [String] -> Generator ()
saysLn [String
"value' <- ",
                          case ValueConversion
conversion of
                            ValueConversion
ConvertPtr -> String
""
                            ValueConversion
ConvertValue -> String
"HoppyFHR.decode =<< ",
                          String
iterGetConst, String
" iter'"]
                  String -> Generator ()
sayLn String
"go' iter' begin' $ value':acc'"
        Generator ()
ln
        [String] -> Generator ()
saysLn [String
"instance HoppyFHR.HasContents ", String
hsDataName,
                String
" (", HsType -> String
forall a. Pretty a => a -> String
prettyPrint HsType
hsValueTypeConst, String
") where"]
        Generator () -> Generator ()
forall a. Generator a -> Generator a
indent (Generator () -> Generator ()) -> Generator () -> Generator ()
forall a b. (a -> b) -> a -> b
$
          [String] -> Generator ()
saysLn [String
"toContents = HoppyFHR.toContents . ", String
setConstCast]

        -- Only generate a nonconst FromContents instance.
        Generator ()
ln
        [String] -> Generator ()
saysLn [String
"instance HoppyFHR.FromContents ", String
hsDataName,
                String
" (", HsType -> String
forall a. Pretty a => a -> String
prettyPrint HsType
hsValueType, String
") where"]
        Generator () -> Generator ()
forall a. Generator a -> Generator a
indent (Generator () -> Generator ()) -> Generator () -> Generator ()
forall a b. (a -> b) -> a -> b
$ do
          String -> Generator ()
sayLn String
"fromContents values' = do"
          Generator () -> Generator ()
forall a. Generator a -> Generator a
indent (Generator () -> Generator ()) -> Generator () -> Generator ()
forall a b. (a -> b) -> a -> b
$ do
            String
setNew <- Class -> String -> Generator String
forall name.
IsFnName String name =>
Class -> name -> Generator String
toHsClassEntityName Class
set String
"new"
            String
setInsert <- Class -> String -> Generator String
forall name.
IsFnName String name =>
Class -> name -> Generator String
toHsClassEntityName Class
set String
"insert"
            [String] -> Generator ()
saysLn [String
"set' <- ", String
setNew]
            [String] -> Generator ()
saysLn [String
"HoppyP.mapM_ (", String
setInsert, String
" set') values'"]
            String -> Generator ()
sayLn String
"HoppyP.return set'"

  in Contents :: Class -> Class -> Class -> Contents
Contents
     { c_set :: Class
c_set = Class
set
     , c_iterator :: Class
c_iterator = Class
iterator
     , c_constIterator :: Class
c_constIterator = Class
constIterator
     }

-- | Converts an instantiation into a list of exports to be included in a
-- module.
toExports :: Contents -> [Export]
toExports :: Contents -> [Export]
toExports Contents
m = ((Contents -> Class) -> Export) -> [Contents -> Class] -> [Export]
forall a b. (a -> b) -> [a] -> [b]
map (Class -> Export
forall a. Exportable a => a -> Export
Export (Class -> Export)
-> ((Contents -> Class) -> Class) -> (Contents -> Class) -> Export
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Contents -> Class) -> Contents -> Class
forall a b. (a -> b) -> a -> b
$ Contents
m)) [Contents -> Class
c_set, Contents -> Class
c_iterator, Contents -> Class
c_constIterator]