- commit
- 7d69f11
- parent
- 1703c53
- author
- Evgenii Akentev
- date
- 2023-04-01 00:27:33 +0400 +04
[row-handle]: add examples of row types
1 files changed,
+26,
-0
+26,
-0
1@@ -25,3 +25,29 @@ getWeatherData = getMethod @"getWeatherData"
2
3 getWindData :: Handle -> Location -> Day -> IO WindProvider.WindSpeed
4 getWindData = getMethod @"getWindData"
5+
6+-- Some examples of what else is possible with row types.
7+
8+-- We can remove an item from the record
9+type WindAndTemperatureMethods = Methods .- "getWeatherData"
10+
11+test1 :: Rec WindAndTemperatureMethods -> Rec (WindProvider.Methods .+ TemperatureProvider.Methods)
12+test1 = id
13+
14+-- It's possible to override methods
15+type MethodsWithUpdatedWeatherData = ("getWeatherData" .== (Location -> Day -> IO Int)) .// Methods
16+
17+test2 :: Rec MethodsWithUpdatedWeatherData -> Rec (("getWeatherData" .== (Location -> Day -> IO Int)) .+ WindProvider.Methods .+ TemperatureProvider.Methods)
18+test2 = id
19+
20+-- And to remove them by taking a row difference
21+type MethodsWithoutWeatherData = Methods .\\ ("getWeatherData" .== (Location -> Day -> IO WeatherData))
22+
23+test3 :: Rec MethodsWithoutWeatherData -> Rec WindAndTemperatureMethods
24+test3 = id
25+
26+-- The minimum join of the two rows.
27+type JoinedMethods = Methods .\/ Methods
28+
29+test4 :: Rec JoinedMethods -> Rec Methods
30+test4 = id