4 ms·
I didn't read this closely, but are those dependent types or just type-level integer literals? Can you use variables and/or arithmetic operations on the type in
by pron 9y ago
I didn't read this closely, but are those dependent types or just type-level integer literals? Can you use variables and/or arithmetic operations on the type index? If you can't instantiate the type with non-literals, then these aren't dependent types. Dependent types are types that depend on (i.e., the type constructors are functions of) actual values of the language, not types that are parameterized by other types (even if the syntax allows naming a type '42', which just looks like a value).
- lmm 9y agoThe series is about dependent types, it doesn't look like it's got as far as actual dependent types in part 1: > what if we wanted to generate a network that has runtime-determined size (For example, getting the size from user input)? What if we wanted to load a pre-trained network whose size we don’t know? How can we manipulate our networks in a “dynamic” and generic way that still gives us all of the benefits of type-safe programming? We’ll found out next post!
- unhammer 9y agoSee https://blog.jle.im/entry/practical-dependent-types-in-haskell-2.html https://blog.jle.im/entry/practical-dependent-types-in-haske... where you get this function definition: https://github.com/mstksg/inCode/blob/master/code-samples/dependent-haskell/NetworkTyped2.hs#L205-213 https://github.com/mstksg/inCode/blob/master/code-samples/de... I liked this article: https://ren.zone/articles/safe-money https://ren.zone/articles/safe-money where they get e.g. an ExchangeRate "USD" "JPY" type from input that has a different type from ExchangeRate "EUR" "JPY" (and thus can't be used to convert euros, only US dollars).
- whateveracct 9y agoGHC Haskell type-level Integer literals can constructed from non-literal just fine :) https://hackage.haskell.org/package/base-4.7.0.2/docs/GHC-TypeLits.html#v:someNatVal https://hackage.haskell.org/package/base-4.7.0.2/docs/GHC-Ty... There are type-level operators as well for arithmetic, but in my experience it’s a bit less pleasant than working with Peano Nats.
- pron 9y agoAnd can you say that a type is indexed by, say, an even number? How do you prove that?
- catnaroek 9y agoA dependent type system needn't be able to express that a type is indexed by an even number. You can have dependent types without type-level computation, for example, by requiring that types be parameterized by nonexpansive expressions - which is nevertheless already more powerful than what Haskell's type system offers. This restriction might even be a good thing for type inference.
- whateveracct 9y agoWith TypeLits, idk if that’s possible without some cheating. But that’s because (as the module name implies) these are type literals and mostly focused on having Integers that can go from type to term and vice-versa. I can definitely do that with Singleton peano Nats pretty easily. I’ll end up with a function of type SNat n -> Maybe (IsEven n) Where IsEven n is some structural proof of even-ness data IsEven (n :: Nat) where ZEven :: IsEven Z SEven :: forall (n ::Nat). IsEven n -> IsEven (S (S n)) I wrote this on my phone, but I’m sure it’s possible and kinda easy to work with at that.
- catnaroek 9y agoAgreed wholeheartedly. What this article shows is fundamentally no different from C++ templates manipulating `int`s (IOW, not dependent types), except for the richer selection of (promoted) data types.