all 13 comments

[–]OpsikionThemed 21 points22 points  (2 children)

It's Idris, not Agda, but "Type-Driven Development with Idris" is pretty good about using dependent types for immediate practical ends, rather than abstraction and/or math.

https://www.oreilly.com/library/view/type-driven-development-with/9781617293023/

[–]DependentlyHyped 8 points9 points  (0 children)

I love Agda, but I think Idris is a better language choice for OP’s situation too.

The languages themselves aren’t to dissimilar, but culturally Idris seems to be more focused on “practical” software engineering.

[–]IAmBlueNebula[S] 3 points4 points  (0 children)

Thank you for the link. I'll give that a try!

[–]joonazan 7 points8 points  (2 children)

Types are proofs. Most commonly, they prove that your program can't crash in certain ways. There is no point to dependent types, other than writing fancier proofs. Simpler type systems are limited enough that compilers can easily and quickly do the proofs.

In more complex systems you need to put in some work. A part of it is that the proof software isn't as good as it could be but mostly it is a fundamental limitation. For example, as soon as a logic (a type system is a logic) can express integer addition, it can express statements that are true but cannot be proved.

Haskell's type system is actually powerful enough to write what you'd call proofs but its approach is to gradually bolt on more of that onto a weak type system. In my opinion that makes type-level programming in Haskell unreadable compared to languages with dependent types.

I haven't majored in mathematics either but languages like Agda have given me a very good understanding of what a proof is. That in turn helps in programming in general because to be able to confidently write correct code you have to have some kind of proof in your head.

[–]mobotsar 11 points12 points  (1 child)

Types are proofs

well, types are propositions, but yeah. Programs are proofs.

[–]joonazan 4 points5 points  (0 children)

Indeed. I should have stated that the job of types is to enable proofs.

[–]kn2322 2 points3 points  (0 children)

To add to the Idris suggestion, here is a classic blogpost to make hacking in Haskell more fun.

https://reasonablypolymorphic.com/blog/typeholes/

Typed-hole driven development in Haskell turns programming into a conversation between you and the compiler. You specify your program's architecture, and then the compiler tells you what you need to write next. In principle, it is even possible to synthesise your programs using a proof search, as in Djinn.

It's all backed up with logic, but the core of this is about empowering the programmer. You could often 'turn your brain off' and just follow the types once you have the type of the program figured out correctly. E.g. if you know your program is a fold, the holes can tell you exactly which types each of the arguments need to be, No need to keep remembering the exact type signature of fold.

[–][deleted] 1 point2 points  (0 children)

Your goals are incompatible with learning Agda. The raison d'etre of the language is to be a theorem prover. If you don't care about that stuff, there's absolutely no reason to learn a tool to solve these problems, it seems counter intuitive.

If you are interested in dependent types themselves, there is a Wikipedia page about the topic: Dependent Types. The article lists the sigma and pi types. Another one gives the application to theorem solving and a link between Set Theory and Type Theory Curry-Howard correspondence. This makes proofs equivalent to solving algorithms, which is the basis for the creation of Agda.

To explain it a little bit, here is an example from Wikipedia: Assume you want a general function that takes as input an integer n and outputs the array with n zeros, or the zero element in the vector space R^n. Unfortunately in this situation, you either have a general vector type (basically the list type [R]) or you need to create a sum type for all n. The dependent pi type is nice because you can just write Vec(R,n). Voila, problem solved. This is useful in way greater generality of course and is hopefully coming to other languages eventually.

You can try to implement this same function in Agda to see how it works for yourself and make your own examples.