Stream: beginners

Topic: wildcard type


view this post on Zulip Prajwal S N (Oct 07 2022 at 19:23):

I'm not quite understanding the difference between these two:

Num a -> Bool
Num * -> Bool

What exactly does the * indicate here? I'm also slightly confused about why numbers are of the type Num * instead of Num by default

view this post on Zulip jan kili (Oct 07 2022 at 19:25):

In a vacuum, those two lines are equivalent

view this post on Zulip jan kili (Oct 07 2022 at 19:27):

The second half of that type (whether it's * or a or apples or Integer) describes what kind of number (Num) it is - it's like a type adjective

view this post on Zulip jan kili (Oct 07 2022 at 19:28):

If it's lowercase or *, it's a placeholder for a specific adjective like Integer

view this post on Zulip jan kili (Oct 07 2022 at 19:29):

The lowercase letters/words are for referencing it and keeping track of matches, like this:

Num a, Num *, Num b -> { foo: Num b, bar: Num a }

view this post on Zulip jan kili (Oct 07 2022 at 19:30):

The asterisk means it doesn't have to match any others in the signature

view this post on Zulip Prajwal S N (Oct 07 2022 at 19:31):

Got it :thumbs_up: thank you!

view this post on Zulip jan kili (Oct 07 2022 at 19:32):

TLDR, the way to write "any kind of number" is Num x, where x is * or any identifier that starts with a lowercase letter

view this post on Zulip jan kili (Oct 07 2022 at 19:34):

I think Int * is a shorthand/alias for Num (Integer *), because there are subtypes of integers, too (I think size & signedness, like U8 vs. I128)

view this post on Zulip Alexander McLin (Feb 02 2023 at 21:17):

Adding new question about wildcard type to this stream, the tutorial says List * is the type for the empty list [] so it make me think that a function with the type List * -> List * would only accept and return an empty list. But the tutorial seem to imply that if List * is the type of a function argument than it means a list of any type but if it is used for a return value then it means only the empty list. I find this confusing, why would List * in one context mean an arbitrary list but the empty list in another context?

Additionally, when testing out in the repl, it says List.isEmpty's type is List a -> Bool instead of List * -> Bool in the tutorial. Is the difference significant?

view this post on Zulip Folkert de Vries (Feb 02 2023 at 21:19):

naming the type variable (so using a instead of *) can be helpful when there are multiple type variables at play

view this post on Zulip Folkert de Vries (Feb 02 2023 at 21:19):

if I said to you: make me a list of an arbitrary type, how would you go about it?

view this post on Zulip Folkert de Vries (Feb 02 2023 at 21:20):

the problem is: you don't know what the element type will be, so you cannot actually create any elements

view this post on Zulip Folkert de Vries (Feb 02 2023 at 21:20):

hence the only list you can make, from scratch, that has an arbitrary element type, is the empty list

view this post on Zulip Folkert de Vries (Feb 02 2023 at 21:21):

so in this way, the element list and "a list with elements of an arbitrary type" are related

view this post on Zulip Folkert de Vries (Feb 02 2023 at 21:22):

but as you notice, they are not the same: in the input of a function, we can say we make no assumptions about the element type. This is what isEmpty does: it does not matter what the element type is if all we want to do is see whether the list is empty

view this post on Zulip Alexander McLin (Feb 02 2023 at 21:45):

Folkert de Vries said:

naming the type variable (so using a instead of *) can be helpful when there are multiple type variables at play

I see, that sort of make sense to me, my take away from your comment is that it's about describing what a type can be versus being able to construct a value satisfying the type which are two different things.


Last updated: Jul 06 2025 at 12:14 UTC