From: Evgenii Akentev Date: Fri, 31 Mar 2023 20:27:33 +0000 (+0400) Subject: [row-handle]: add examples of row types X-Git-Url: https://git.ak3n.com/?a=commitdiff_plain;h=HEAD;p=handle-examples.git [row-handle]: add examples of row types --- diff --git a/row-handle/domain/WeatherProvider.hs b/row-handle/domain/WeatherProvider.hs index 2a18204..0194e9a 100644 --- a/row-handle/domain/WeatherProvider.hs +++ b/row-handle/domain/WeatherProvider.hs @@ -25,3 +25,29 @@ getWeatherData = getMethod @"getWeatherData" getWindData :: Handle -> Location -> Day -> IO WindProvider.WindSpeed getWindData = getMethod @"getWindData" + +-- Some examples of what else is possible with row types. + +-- We can remove an item from the record +type WindAndTemperatureMethods = Methods .- "getWeatherData" + +test1 :: Rec WindAndTemperatureMethods -> Rec (WindProvider.Methods .+ TemperatureProvider.Methods) +test1 = id + +-- It's possible to override methods +type MethodsWithUpdatedWeatherData = ("getWeatherData" .== (Location -> Day -> IO Int)) .// Methods + +test2 :: Rec MethodsWithUpdatedWeatherData -> Rec (("getWeatherData" .== (Location -> Day -> IO Int)) .+ WindProvider.Methods .+ TemperatureProvider.Methods) +test2 = id + +-- And to remove them by taking a row difference +type MethodsWithoutWeatherData = Methods .\\ ("getWeatherData" .== (Location -> Day -> IO WeatherData)) + +test3 :: Rec MethodsWithoutWeatherData -> Rec WindAndTemperatureMethods +test3 = id + +-- The minimum join of the two rows. +type JoinedMethods = Methods .\/ Methods + +test4 :: Rec JoinedMethods -> Rec Methods +test4 = id \ No newline at end of file