Fix backpack-handles example with two signatures
authorEvgenii Akentev <i@ak3n.com>
Fri, 8 Jan 2021 20:29:03 +0000 (01:29 +0500)
committerEvgenii Akentev <i@ak3n.com>
Fri, 8 Jan 2021 20:29:03 +0000 (01:29 +0500)
backpack-handles/backpack-handles.cabal
backpack-handles/impl/SuperWeatherReporter.hs

index e8ee369d61a9f7ee194b7356839587158bc5b41e..6cfe4f87359e2bf02fff72cfea75d2669818b7e1 100644 (file)
@@ -7,7 +7,7 @@ maintainer:          i@ak3n.com
 build-type:          Simple
 extra-source-files:  CHANGELOG.md
 
-library domain
+library domain-provider
   hs-source-dirs: domain
   signatures:      WeatherProvider
   default-language: Haskell2010
@@ -17,18 +17,23 @@ library domain-reporter
   hs-source-dirs: domain
   signatures:      WeatherReporter
   default-language: Haskell2010
-  build-depends:    base, domain
+  build-depends:    base, domain-provider
 
-library impl
+library impl-provider
   hs-source-dirs: impl
   exposed-modules: SuperWeatherProvider
-                 , SuperWeatherReporter
-  reexported-modules: SuperWeatherProvider as WeatherProvider,
-    SuperWeatherReporter as WeatherReporter
+  reexported-modules: SuperWeatherProvider as WeatherProvider
   default-language: Haskell2010
   build-depends:    base
 
-library test-impl
+library impl-reporter
+  hs-source-dirs: impl
+  exposed-modules: SuperWeatherReporter
+  reexported-modules: SuperWeatherReporter as WeatherReporter
+  default-language: Haskell2010
+  build-depends:    base, domain-provider
+
+library test-provider
   hs-source-dirs: test-impl
   exposed-modules: TestWeatherProvider
   reexported-modules: TestWeatherProvider as WeatherProvider
@@ -38,8 +43,10 @@ library test-impl
 executable main
   main-is:             Main.hs
   build-depends:       base >=4.13 && <4.14
-                     , impl
-                     , domain
+                     , impl-provider
+                     , impl-reporter
+                     , domain-reporter
+                     , domain-provider
   default-language:    Haskell2010
 
 test-suite spec
@@ -50,8 +57,7 @@ test-suite spec
   build-depends:       base >= 4.7 && < 5
                      , QuickCheck
                      , hspec
-                     , domain
-                     , test-impl
-                     , impl
-  mixins:
-    impl (WeatherProvider as UnusedWeatherProvider, WeatherReporter)
+                     , domain-reporter
+                     , domain-provider
+                     , test-provider
+                     , impl-reporter
index 4a6ed2bfd0700e12238e8deb5a3ce76be2b7a5a8..7eccaa65b9d54f96ae9051fa30f5aaa4a5bbc248 100644 (file)
@@ -1,25 +1,25 @@
 module SuperWeatherReporter where
 
-import qualified SuperWeatherProvider
+import qualified WeatherProvider
 
 type WeatherReport = String
 
-type WeatherProviderHandle = SuperWeatherProvider.Handle
+type WeatherProviderHandle = WeatherProvider.Handle
 
 -- | We hide dependencies in the handle
-data Handle = Handle { weatherProvider :: SuperWeatherProvider.Handle }
+data Handle = Handle { weatherProvider :: WeatherProvider.Handle }
 
 -- | Constructor for Handle
-new :: SuperWeatherProvider.Handle -> Handle
+new :: WeatherProvider.Handle -> Handle
 new = Handle
 
 -- | Domain logic. Usually some pure code that might use mtl, free monads, etc.
-createWeatherReport :: SuperWeatherProvider.WeatherData -> WeatherReport
-createWeatherReport (SuperWeatherProvider.WeatherData temp) =
+createWeatherReport :: WeatherProvider.WeatherData -> WeatherReport
+createWeatherReport (WeatherProvider.WeatherData temp) =
   "The current temperature in London is " ++ (show temp)
 
 -- | Domain logic that uses external dependency to get data and process it.
 getCurrentWeatherReportInLondon :: Handle -> IO WeatherReport
 getCurrentWeatherReportInLondon (Handle wph) = do
-  weatherData <- SuperWeatherProvider.getWeatherData wph "London" "now"
+  weatherData <- WeatherProvider.getWeatherData wph "London" "now"
   return $ createWeatherReport weatherData