4 ms·
so, I'm curious, do you write the type of the function first? When I used to write haskell, I'd very often write a function, iterate on it until it did what I
by mijoharas 6y ago
so, I'm curious, do you write the type of the function first?
When I used to write haskell, I'd very often write a function, iterate on it until it did what I want, then infer the type of the function and insert that into the program. Now, I was relatively new to haskell, so was probably less comfortable writing types than reading them (so I assume it was nicer to have the compiler do that for me, eyeball it to check it's what I meant to do, and put it in).
I'm wondering if someone more familiar would think "alright, what type do I want my function to be", fill that in, and then write the type out?
I definitely agree that a program is more readable with types, which is why I always filled them in (I just did it afterwards!)
- eru 6y agoI do both in Haskell. Sometimes I write the types first and sometimes I write the function first. Usually, the functions with more imperative flavour get their implementation first, and the more functionally flavoured bits get their type first. But that's not always the case. Sometimes I even write the QuickCheck properties first.
- deleted 6y ago[deleted]
- gnulinux 6y agoAgain, can't speak for haskell. In agda you usually have 2 goals creating a function * Proving a property of some other object. In this case you have to write the type first since type is the theorem you want to prove, and implementation is the proof. * Implement a transformation. In this case, as you described you might get away first writing the impl, and then the type, but I personally never even attempt to do that since writing out the type gives me a lot to think about the implementation of the transformation. Once types are explicit, implementation usually ends up being a lot more obvious.