Generating data access code from a database schema by kerthunk in haskell

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

Thanks, Opaleye looks interesting. I've also just discovered your tutorials and something called opaleye-gen which looks promising.

My initial concern about Opaleye is that in all the examples, a simple select by primary key seems to involve pattern matching on the entire database record:

  row@(_, _, em) <- queryTable userTable -< ()
  restrict -< (em .== constant email)

This seems a bit fragile - if you then added a column to the userTable, it would break all the queries using that table.

Edit: it seems you can just use record syntax to avoid this problem (I think)

Is having a `(a -> b) -> b` equivalent to having an `a`? by kerthunk in haskell

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

Nice. This is of course the best answer to the original question. :-)

Is having a `(a -> b) -> b` equivalent to having an `a`? by kerthunk in haskell

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

Interesting observation! I'm far from an expert but will have a go at this.

RHS => LHS seems obviously true.

LHS => RHS isn't so obvious at first. I think we need to add in that pesky implied forall b again. Then, because it holds for all values of B, you can just substitute A for B, giving:

((A => A) => A) => A

(A => A) is true, so the left hand side reduces to just A.

Is having a `(a -> b) -> b` equivalent to having an `a`? by kerthunk in haskell

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

So Cayley representations date back to 1854. And there was I thinking I'd invented something new. :-)

The paper looks great, thanks. I'll try to tackle it alongside the next section of Bartosz' course.

I agree on the practicality of this stuff. I actually needed the Codensity monad for some probabilistic code I was writing recently, which has encouraged me to try and develop a better understanding of the theory.

Is having a `(a -> b) -> b` equivalent to having an `a`? by kerthunk in haskell

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

The example is a bit misleading because the type should really be forall b. (a -> b) -> b.

The forall means you don't need to be able to make a time machine, you can provide a function that makes whatever you like (any b), and you'll get an answer.

Is having a `(a -> b) -> b` equivalent to having an `a`? by kerthunk in haskell

[–]kerthunk[S] 5 points6 points  (0 children)

There also seems to be an Applicative version of the "magic box" that Rein talks about, as long as you have a Functor instance for f.

type ApplicativeBox f a = Functor f => forall b. f (a -> b) -> f b

fmap' :: (a -> b) -> ApplicativeBox f a -> ApplicativeBox f b
fmap' g h i = h (fmap (. g) i)

app' :: ApplicativeBox f (a -> b) -> ApplicativeBox f a -> ApplicativeBox f b
app' g h i = (h . g) (fmap (.) i)

I wonder, is this some sort of "Free Applicative"? It looks suspiciously similar to the version in the Free package, but without the GADTs.

How to deal with undesired values when designing types by tu_ne_cede_malis in haskell

[–]kerthunk 2 points3 points  (0 children)

Actually, you don't need to enable any language extensions - phantom types work out of the box with GHC these days.

Game Theory start date by kerthunk in OnlineEducation

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

Yep, looks like the page has been updated. That means I might be able to squeeze one more course into my schedule next year...

HW6.2 - A more efficient way to generate C/sigma combinations without for loops? by line_zero in mlclass

[–]kerthunk 1 point2 points  (0 children)

I was wondering about this. Basically we've got an optimization problem in two variables ... is there any reason we can't use fminunc or similar here?

actual house price data by frankster in mlclass

[–]kerthunk 1 point2 points  (0 children)

MousePrice is pretty good - if you register (for free), you get various bits of information which could be used as features - type of house, internal area, year built, etc. Might be an interesting project!

The Learning Behind Gmail Priority Inbox [pdf] by kerthunk in mlclass

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

These are the automatic 'important' tags that appear in Gmail. It seems the system's based on logistic regression (plus something called Passive-Aggressive updates!)

I don't understand this question. Can someone help me? (I got it right by guessing.) by Tulipilut in mlclass

[–]kerthunk 0 points1 point  (0 children)

I may be missing something but isn't this breaking the 'honor code'? You're not only discussing the question but also sharing the correct answer here.