Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule inputs alternate hasinput class #4406

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

nlander
Copy link
Contributor

@nlander nlander commented Sep 18, 2024

Instead of type level list inclusion for HasInput, this enumerates all of the instances and ValidInputs is a sum type.

@michaelpj
Copy link
Collaborator

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

@nlander
Copy link
Contributor Author

nlander commented Sep 22, 2024

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 ValidInputs kind and the InputType kind.

@michaelpj
Copy link
Collaborator

The problem with that approach is that for some rules, both project haskell files and dependency haskell files are valid inputs.

Sure, so then you would need to have ProjectOrHaskellFile as the rule input and your RuleInputFromFilePath would be a bit more complex. It doesn't solve the "open universe of input file types" problem, but I think it's maybe a little nicer than what you're doing right now, and does solve the "this rule should take an input of type ()" problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants