(Background: https://stackoverflow.com/questions/69360027/list-set-should-be-a-sort-but-it-isnt)
So what's the deal with List A = ⊤ + A × List A?
Here's a list of types translated into a product of types:
The catch is that (A × ...) is a type, and (A ∷ ...) isn't. Seems to me that List and component-wise product are not the same after all... A little weird.
Maybe it's obvious to some.
So what's the deal with List A = ⊤ + A × List A?
Here's a list of types translated into a product of types:
map : List Set → Set map [] = ⊤ map (A ∷ t) = A × (map t)
The catch is that (A × ...) is a type, and (A ∷ ...) isn't. Seems to me that List and component-wise product are not the same after all... A little weird.
Maybe it's obvious to some.
no subject
Date: 2021-10-11 11:51 am (UTC)no subject
Date: 2021-10-11 10:09 pm (UTC)no subject
Date: 2021-10-12 09:37 am (UTC)no subject
Date: 2021-10-12 09:58 am (UTC)But the confusing bit here is that (,) in Idris is used in two contexts, and in this case you have to disambiguate what context this is. In this situation (,) is a type former expression, not construction of a tuple.
Similarly in the original problem statement (_×_) is a type former. Still it takes some effort to see how a list of types can be turned into a tuple type, but not the other way around - can't project individual types out of the tuple to construct a list of types.
no subject
Date: 2021-10-12 10:09 am (UTC)x : fst (swap (23, Int))
x = 42
Even this:
x : let p = (23, Int) in fst (swap p)
x = 42
So I understand why Idris is fine with your code but don't understand why Agda is unhappy. I don't know Agda though.
no subject
Date: 2021-10-12 10:43 am (UTC)I don't propose that it has to compile, but that's the thing, essentially: you can pattern-match the pair (you can project the components of the pair with fst and snd), but you can't pattern-match type-former. Can you project type a from (a, b)? How about (a->b)?
Ooh, even better, let's start with something simpler, not the inverse entirely:
I get
no subject
Date: 2021-10-12 11:31 am (UTC)You can still extract `a` from `(a,b)` if you know it's `(a,b)`.
no subject
Date: 2021-10-12 01:52 pm (UTC)Here it can tell that Unit is mmm xs.
Let's pause for a moment. You can extract `a` from `(a, b)`, when `(,)` is the tuple constructor, no doubt about that. But is it a tuple constructor in `mmm (h :: t) = (h, mmm t)`?
no subject
Date: 2021-10-13 10:21 am (UTC)no subject
Date: 2021-10-13 12:47 pm (UTC)My thinking is that in the latter context `(,)` has the same role as `->` - a type former of arity 2. Then `A -> B` is only a way to say "a type corresponding to a pair of types A and B [with the special meaning conferred by _->_ to the entire family of such types]" - but you can't extract A from `A -> B` - in fact, `A` doesn't exist in any form in `A -> B`. In the same manner `A` doesn't exist in `(A, B): Type`, just Idris adds confusion by using `(,)` for both type declaration and instance (de-)construction. In Agda type is declared with `A × B : Set`, and values of that type are constructed as `(a : A , b : B) : A × B`.
My original post was about confusion I noticed in my reasoning - are we in the world of types or in the world of values when we say a List is an n-ary product of all the values in the list; and what world we are in, when the values of the List are types themselves.
no subject
Date: 2021-10-13 01:39 pm (UTC)