Given an type involving type variables, is there a way to defined an infinite list of type variables in which no type variable are ever repeated?
Let me provide more context with my question. I’m working on a type inference of my own in Haskell. My data type looks like this:
data Ty = TyUnit
| TyVar String
| TyBool
| TyInt
| TyBoolList
| TyIntList
| Arrow Ty Ty
I gave the definition of the type above. I believe that the function is supposed to generate an infinite list of variable names. I’m just confused on how to proceed and the actual implementation of the question.
Here you go.
allTys nconstructs a type tree of height n. Here height ofArrow x yis height of x + height of y + 1 and height of everything else is 0. The construction is very basic. I’m not sure if it can be done faster. Ask in the comments, if it needs more explaining.Also, in case that is needed, this is how to get all strings of an alphabet (say
['a'..'z']) .The idea that a long string is a
somechar:shortstring. Note that the empty string is included.