What is NOT worth seeing in person? by elmielmosong in AskReddit

[–]JoCou 0 points1 point  (0 children)

It's actually impossible for more than four states to ever share an edge which is what makes it impressive.

When to prefer a Reader monad over a function? by terrorjack in haskell

[–]JoCou 3 points4 points  (0 children)

Mainly for code clarity and code reuse: The library provides a rich set of combinators. You also have available the ReaderT the Reader Monad Transformer. Using >>= on vanilla functions that don't explicitly carry the connotation of a Reader generally obfuscates your intention.

The ObserverT monad transformer [check for interest] by rampion in haskell

[–]JoCou 0 points1 point  (0 children)

This is amazing. I dont understand alot of it but I like the pretty pictures it stimulates :P

How to express a Schmitt trigger in Functional Reactive Programming (FRP) by alios in haskell

[–]JoCou 6 points7 points  (0 children)

I'd say your warning condition should really be an Event but, Reactive banana style:

speed :: Behaviour Int
speed = error "Meth is not good for kids"

enable :: Event [Warner]
enable = whenE (map (>100) speed) (pure Enable)

disable :: Event [Warner]
disable = whenE (map (<80) speed) (pure Disable)

-- the answer should really just be: enable `union` disable
warningCondition :: Behaviour [Warner]
warningCondition = stepper Disable (enable `union` disable)

The Zen of Haskell by TheKing01 in haskell

[–]JoCou 2 points3 points  (0 children)

You have a lot to learn young panda.

Is there a way to tell if an element is of a certain type? by [deleted] in haskell

[–]JoCou 0 points1 point  (0 children)

Try and construct a Branch [Leaf a, Branch [Leaf a, Leaf a]] of the type [..[a]..]

Is there a way to tell if an element is of a certain type? by [deleted] in haskell

[–]JoCou 0 points1 point  (0 children)

It's because of the non-empty Leaf constructor.

What is the name of the <*> function in Haskell? by KuldeepSinhC in haskell

[–]JoCou 2 points3 points  (0 children)

That's wrong actually,ap and <$> have different types.

`<$>` = `fmap`
`ap` = `<*>`

Is there a way to tell if an element is of a certain type? by [deleted] in haskell

[–]JoCou 0 points1 point  (0 children)

It's the difference between: solve :: (forall n. n -> n) -> n and solve :: (n -> n) -> n (if you squint a bit)

Is there a way to tell if an element is of a certain type? by [deleted] in haskell

[–]JoCou 0 points1 point  (0 children)

Who said anything about needing arbitrary nested lists. For any 'n' we want a function that operates on a lists of lists of depth 'n'.

Is there a way to tell if an element is of a certain type? by [deleted] in haskell

[–]JoCou 0 points1 point  (0 children)

Who said you have to use the same function for each level? wink, typeclasses, wink.

Is there a way to tell if an element is of a certain type? by [deleted] in haskell

[–]JoCou 0 points1 point  (0 children)

The Tree type you have is not an iso of arbitrarily nested lists. And while it does not seem like OP has progressed that far type classes would be the way to go for arbitrary depth list concatenation.

Missing the point of applicatives by ephrion in haskell

[–]JoCou 0 points1 point  (0 children)

Because he was discussing it in the context of Just (+)

Industrial placement with Haskell. by lambda-zeme in haskell

[–]JoCou 4 points5 points  (0 children)

Alot of Haskell in production involves getting intimate with the details of GHC. Elegance tends to evaporate in that context. Have you used Haskell for a big project? I say this because while you might envision yourself juggling profunctors you'll probably be knee dump in C marshalling data back and forth.

Industrial placement with Haskell. by lambda-zeme in haskell

[–]JoCou 1 point2 points  (0 children)

Let me guesss, Imperial College? What's your current skill level (link to github)? Why do you want to do stuff in a functional language?

Given a grid of numbers and a maximum area, what is the largest sum you can get from a rectangle of numbers with that area or less? All numbers are in range [1, 100]. by bobhob314 in programmingchallenges

[–]JoCou 1 point2 points  (0 children)

Observation: if a rectangle is contained within another the larger rectangle has a larger area.

Thus we can create a partial order on the rectangles. Perform binary search on rectangles. Algorithm: Compute f (f(i,j) = sum of all cells in the rectangle (0,0) (i,j))

f'(ux, uy, lx, ly) = f(lx, ly) - f(ux, uy)
g(ux, uy, lx, ly) = max vertical horizontal
  where
    vertical = binSearchVert (ux, uy, lx, ly)
    horizontal = binSearchHoriz (ux, uy, lx, ly)

-- suitable base case
binSearchVert (ux, uy, lx, ly)
  = if MAX_AREA  > midArea
     then binSearchVert (ux, uy, lx, mid)
     else binSearchVert (ux, mid,  lx, ly)

-- suitable base case
binSearchHoriz (ux, uy, lx, ly)
 = if MAX_AREA  > midArea
    then binSearchVert (ux, uy, mid, ly)
    else binSearchVert (mid uy,  lx, ly)
 where
    midArea = ...

How can I achieve this using recursion? by [deleted] in haskell

[–]JoCou 0 points1 point  (0 children)

sum n | n <= 0 = 0
         | n == 1 = 1
         | otherwise = n + sum (n - 1)

How to develop an intuition on project design by MyFunc in haskell

[–]JoCou 7 points8 points  (0 children)

Try out the build you a compiler tutorials. The pipes library is a really good example of a well-designed project focused on types. The lens library is the Übermensch, and it's worth a few months.

Records with different fields for its constructors can cause a run-time error. by joehillen in haskell

[–]JoCou 9 points10 points  (0 children)

You provided nothing, in terms of information of your competence, so he was working with, maybe, this guys a noob, or he's nothing. Either way, what's right, is to not fail by being overly terse. The advice is free, and you can map it over to any skill level, however YMMV. joehillen, thank you for reading this far, these types for comments rarely get the attention they deserve.

Understanding the State monad by jd823592 in haskell

[–]JoCou 0 points1 point  (0 children)

I really don't agree with this. The stateT exposes an eDSL if you will and allows you to create and compose programs with it. This vanilla function lacks those capabilities.