repos / handle-examples.hs.git


commit
bc90443
parent
5403ccb
author
Evgenii Akentev
date
2021-01-09 19:40:35 +0400 +04
[vinyl-handle]: implement providers properly
5 files changed,  +38, -15
M vinyl-handle/Main.hs
+7, -2
 1@@ -1,6 +1,8 @@
 2 module Main where
 3 
 4 import qualified SuperWeatherProvider
 5+import qualified SuperWindProvider
 6+import qualified SuperTemperatureProvider
 7 import qualified WeatherProvider
 8 import qualified WeatherReporter
 9 
10@@ -8,7 +10,10 @@ import qualified WeatherReporter
11 -- our concrete implementation of `WeatherProvider`.
12 main :: IO ()
13 main = do
14-  let wph = SuperWeatherProvider.new
15-  let wrh = WeatherReporter.new wph
16+  let
17+    wp = SuperWindProvider.new
18+    tp = SuperTemperatureProvider.new
19+    wph = SuperWeatherProvider.new wp tp
20+    wrh = WeatherReporter.new wph
21   weatherReportInLondon <- WeatherReporter.getCurrentWeatherReportInLondon wrh
22   putStrLn weatherReportInLondon
A vinyl-handle/impl/SuperTemperatureProvider.hs
+12, -0
 1@@ -0,0 +1,12 @@
 2+module SuperTemperatureProvider where
 3+
 4+import Data.Vinyl
 5+import TemperatureProvider
 6+import QueryTypes
 7+
 8+new :: Handle
 9+new = Field getSuperTemperatureData
10+  :& RNil
11+
12+getSuperTemperatureData :: Location -> Day -> IO Temperature
13+getSuperTemperatureData _ _ = return 30
M vinyl-handle/impl/SuperWeatherProvider.hs
+5, -13
 1@@ -2,22 +2,14 @@ module SuperWeatherProvider where
 2 
 3 import Data.Vinyl
 4 import WeatherProvider
 5-import TemperatureProvider (Temperature)
 6-import WindProvider (WindSpeed)
 7+import qualified TemperatureProvider
 8+import qualified WindProvider
 9 import QueryTypes
10 
11-new :: Handle
12-new = Field getSuperWeatherData
13-  :& Field getSuperWindData
14-  :& Field getSuperTemperatureData
15-  :& RNil
16+new :: WindProvider.Handle -> TemperatureProvider.Handle -> Handle
17+new wp tp = Field getSuperWeatherData
18+  :& RNil <+> wp <+> tp
19 
20 -- | This is some concrete implementation `WeatherProvider` interface
21 getSuperWeatherData :: Location -> Day -> IO WeatherData
22 getSuperWeatherData _ _ = return $ WeatherData 30 10
23-
24-getSuperTemperatureData :: Location -> Day -> IO Temperature
25-getSuperTemperatureData _ _ = return 30
26-
27-getSuperWindData :: Location -> Day -> IO WindSpeed
28-getSuperWindData _ _ = return 5
A vinyl-handle/impl/SuperWindProvider.hs
+12, -0
 1@@ -0,0 +1,12 @@
 2+module SuperWindProvider where
 3+
 4+import Data.Vinyl
 5+import WindProvider
 6+import QueryTypes
 7+
 8+new :: Handle
 9+new = Field getSuperWindData
10+  :& RNil
11+
12+getSuperWindData :: Location -> Day -> IO WindSpeed
13+getSuperWindData _ _ = return 5
M vinyl-handle/vinyl-handle.cabal
+2, -0
1@@ -21,6 +21,8 @@ library domain
2 library impl
3   hs-source-dirs: impl
4   exposed-modules: SuperWeatherProvider
5+                 , SuperWindProvider
6+                 , SuperTemperatureProvider
7   default-language: Haskell2010
8   build-depends:    base, domain, vinyl
9