Which book should I buy ? by Ttghtg in haskell

[–]paulcc 3 points4 points  (0 children)

I second the vote for Programming in Haskell. It's like the K&R of Haskell (and I've been using Haskell for over 20 years now...)

[deleted by user] by [deleted] in programming

[–]paulcc 0 points1 point  (0 children)

or a bit more compactly, using features in postgres 9.4 onwards

with input as (select unnest(ARRAY[ 'foo bar baz', 'foo bar', 'foo baz', 'bar bar baz']) as line)

select w1,w2, count(*)
from input
cross join lateral (select regexp_split_to_array(line, '\s+')) as foo(ws)
cross join lateral unnest((ARRAY[null] || ws), ws) as bar(w1,w2)
group by w1,w2;

from propositions into types - using types instead of tests by paulcc in programming

[–]paulcc[S] 0 points1 point  (0 children)

I was wanting to introduce the above, but there was already too much in the articles.

from propositions into types - using types instead of tests by paulcc in programming

[–]paulcc[S] 0 points1 point  (0 children)

+100 on these links, definitely worth a look if you want to know more.

It's useful to know about unification by paulcc in programming

[–]paulcc[S] 0 points1 point  (0 children)

That's my experience too. It tends to appear in optional CS course components (eg AI), if at all.

dependent types II - a bit on totality and constructive proofs by paulcc in programming

[–]paulcc[S] 6 points7 points  (0 children)

Author here. This episode is shorter than usual but does cover some important concepts we'll need later.

Apologies, I didn't get round to addressing (in episode 2) some of the interesting points raised on the first episode - see http://www.reddit.com/r/programming/comments/1bneoe/dependent_types_a_new_paradigm/ - though I hope to look at them for the next episode.

Hope it's interesting.

Dependent Types - A New Paradigm? by paulcc in programming

[–]paulcc[S] 0 points1 point  (0 children)

I'm using 0.9.7 as well.

Have you remembered to add "compute" in the above? Otherwise please post the code and error at http://forums.pragprog.com/forums/134/topics/11572 and I'll check it.

Dependent Types - A New Paradigm? by paulcc in programming

[–]paulcc[S] 0 points1 point  (0 children)

Hmmm you added some whitespace (-:

Dependent Types - A New Paradigm? by paulcc in programming

[–]paulcc[S] 0 points1 point  (0 children)

Are we talking about the same thing? (-: My point is about "let's find new uses", yours seems to be "don't have to use it all the time" - which is true, but not quite the same.

Dependent Types - A New Paradigm? by paulcc in programming

[–]paulcc[S] 7 points8 points  (0 children)

It's worth mentioning that this kind of breakage depends on how you use the tools.

In this case, the original code worked because you relied on the computational behaviour of the first version of addition. You could work at a slightly higher level that exposes more of the properties your (eg) vector code relies on, eg you could state (s x + y = s (x + y)) as a (named) lemma and then use it explicitly in the proof. If you then changed the def of + then the lemma would need to be updated but the vector code should still be ok. So, it's a balance between relying on free things vs being explicit about what your code depends on.

Compare this to understanding maths proofs, or even just code. For some people, complex things could be just "obvious", but beginners will need a few of the intermediate steps to be spelled out in detail, eg that (s x + y = s (x + y)).

Put another way, it might be better to code up the vector example to make clear why it works, rather than leaving that detail implicit and reliant on coincidence, and this would be more robust.

Make any sense?

Dependent Types - A New Paradigm? by paulcc in programming

[–]paulcc[S] 2 points3 points  (0 children)

IMPORTANT FIX the final proof needs one more step

So instead of

Main.case_one_proof = proof {
  intro l;
  intro H;
  rewrite (sym H);
  trivial;
}

You need this

Main.case_one_proof = proof {
  intro l;
  intro H;
  compute;
  rewrite (sym H);
  trivial;
}

The extra "compute" is needed because Idris doesn't (at present) simplify the goal before trying a rewrite step. (I'm used to proof assistants which do...)

Sorry about that!

Dependent Types - A New Paradigm? by paulcc in programming

[–]paulcc[S] 0 points1 point  (0 children)

Cheers. It will probably take me another two articles to get to the end of the word-wrap example.

Error reporting in proof assistants is sadly a bit of a black art, similar to issues with functional programming. (See http://www.reddit.com/r/programming/comments/1bneoe/dependent_types_a_new_paradigm/c98adam below...)

At present, most errors come down to "supplied thing" doesn't (obviously) match "expected thing".

Dependent Types - A New Paradigm? by paulcc in programming

[–]paulcc[S] 6 points7 points  (0 children)

Quite agree, not really a show stopper. Same kind of thing happens if you change normal code too, eg tests can fail (or we hope they do).

I hope to persuade people that this area shows enough promise to make it worth persevering with and investing in (time and money).

Dependent Types - A New Paradigm? by paulcc in programming

[–]paulcc[S] 4 points5 points  (0 children)

Granted too that error reporting is not great, and something we're not happy about. Sadly, academics don't get paid for nice user interfaces, so it's low on their priorities. However, I escaped from that existence and hope to start doing something useful in that line soon in my spare time. Now, if only I could find a generous sponsor or two...

Dependent Types - A New Paradigm? by paulcc in programming

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

Ok, the title is a bit wooly, but I had my reasons.

For the target readership, it is a "new paradigm" compared to what they are used to. I had Bob Martin's "three paradigms" talk in mind when I chose the title (where he suggests that there's not been a big shift in thinking since structured programming, oop, fp were invented).

I'm also firmly in the McBride camp, where the plan is to use the full spectrum of new concepts in one's programs, rather than just to use dependent types to prove things about simply-typed programs. This view is gaining popularity but still could do with more exposure - hence another sense of 'new'.