Rule inputs alternate hasinput class#4406
Conversation
|
sketch of what I was saying on the call: type family RuleInput k :: Type
newtype ProjectHaskellFile = ProjectHaskellFile NormalizedFilePath
-- examples
type instance RuleInput GhcSession = ProjectHaskellFile
type instance RuleInput GetClientSettings = ()
-- various stuff might require `RuleInputFromFilePath (RuleInput r)`
-- which basically says you have a way to convert a filepath into
-- input for the rule, possibly failing
class RuleInputFromFilePath i where
toRuleInput :: NormalizedFilePath -> Either String i
-- example
someRule = do
...
validFp <- case toRuleInput nfp of
Right p -> pure p
Left e -> ... some error ...
use someRule validFp |
@michaelpj The problem with that approach is that for some rules, both project haskell files and dependency haskell files are valid inputs. This is why I distinguish between the |
Sure, so then you would need to have |
Instead of type level list inclusion for
HasInput, this enumerates all of the instances andValidInputsis a sum type.