I have a question which I hope has a simple answer and will not embarass me too much. When working with functions like this one:
clockPeriod :: forall dom period. (KnownDomain dom, DomainPeriod dom ~ period) => SNat period
(taken from Clash, Clash.Signal)
Its return value depends upon the dom type, but dom is not actually a type parameter. Assuming I have multiple doms in scope, when calling this function, how can I specify which dom I want used?
And does it have a name, a function that has a bound on a type that is not a type parameter?
dom is a type parameter of clockPeriod; it just doesn’t appear in the result type SNat period. (I think that’s what you mean to say?)
You can use type applications to specify specific type arguments for parameterized functions like clockPeriod: clockPeriod @YourDomType is what that would look like. You can see a few examples of this nearby in the Clash documentation.
dom is a type parameter of clockPeriod ; it just doesn’t appear in the result type SNat period . (I think that’s what you mean to say?)
Yes - I guess so.
You can use type applications to specify specific type arguments for parameterized functions like clockPeriod : clockPeriod @YourDomType is what that would look like. You can see a few examples of this nearby in the Clash documentation.
Great, thank you. I was building up to a second question about what those @s were, and now I’m glad at least I didn’t bundle that question into this one.
Aha. You mean the period here is redundant, because it’s already specified by the DomainPeriod dom type parameter? It might just be a convenience function, I’m not sure.
Thanks for giving me this crucial “Phantom Types” term.