Created
October 16, 2023 15:43
-
-
Save kephas/9e486ce0b6a4c2a9c06eadb1615680d2 to your computer and use it in GitHub Desktop.
Type-safe refactoring with ad-hoc polymorphism
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Adhoc where | |
data ClientIdentifier | |
= Admin | |
| User String | |
deriving (Eq, Show) | |
data Settings = Settings | |
{settingAllowList :: [ClientIdentifier]} | |
deriving (Show) | |
clientIsAllowed :: Settings -> ClientIdentifier -> Bool | |
clientIsAllowed settings client = | |
clientIsInAllowList (settingAllowList settings) client | |
clientIsInAllowList :: Foldable t => t ClientIdentifier -> ClientIdentifier -> Bool | |
clientIsInAllowList allowList client = | |
foldr checkOne False allowList | |
where | |
checkOne :: ClientIdentifier -> Bool -> Bool | |
checkOne _ True = True | |
checkOne otherClient False = client == otherClient |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment