How does functions take arguments in both numerical and string type

I know that string type could be made as an interface to a type thought IsString typeclass but surprise to see function take in two formats. How does this work ? How does for example 0.7 is an Pattern Double.

Patterns of numbers are members of the number class, so 0.7 can be a pattern. Tidal/Pattern.hs at main · tidalcycles/Tidal · GitHub

I wonder if by 0.7 Dust might mean the string literal ”0.7”?

If so, Dust, then it isn’t so much that the function can take either a number or a pattern of numbers. It is rather that, through the OverloadedStrings GHC extension and the IsString typeclass, for which Pattern has an instance, tidal’s mininotation parser can convert the overloaded string literal ”0.7” into Pattern Double.

Is that what you were thinking of?

The confusion is that it has to be either of the below example, not both.

speed 0.7
speed "0.7"

What I am asking is that how does 0.7 (not string literal) as an argument works when it also works for "0.7" ?

Ahh, of course. Here I was, for some reason wondering if your message had perhaps lost some quote marks.

re: your latest reply, and to add some detail to yaxu's reply:

Pattern's Fractional typeclass instance provides fromRational :: (Fractional a) => Rational -> Pattern a.

Phrased approximately, the compiler treats numeric literals (like 0.7) as an application of fromRational to a Rational, allowing for the literal value to be converted to the needed Fractional [typeclass instance,] in this case a Pattern.

Good to know. Thank you.

1 Like