From 3ff5b6d3508c2d50e2a176ed2d5f0f1c22afed4a Mon Sep 17 00:00:00 2001 From: Evgenii Akentev Date: Sat, 9 Jan 2021 01:29:03 +0500 Subject: [PATCH] Fix backpack-handles example with two signatures --- backpack-handles/backpack-handles.cabal | 34 +++++++++++-------- backpack-handles/impl/SuperWeatherReporter.hs | 14 ++++---- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/backpack-handles/backpack-handles.cabal b/backpack-handles/backpack-handles.cabal index e8ee369..6cfe4f8 100644 --- a/backpack-handles/backpack-handles.cabal +++ b/backpack-handles/backpack-handles.cabal @@ -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 diff --git a/backpack-handles/impl/SuperWeatherReporter.hs b/backpack-handles/impl/SuperWeatherReporter.hs index 4a6ed2b..7eccaa6 100644 --- a/backpack-handles/impl/SuperWeatherReporter.hs +++ b/backpack-handles/impl/SuperWeatherReporter.hs @@ -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 -- 2.34.1