Conversation started Mar 1, 2018 at 23:10.
Mar 1, 2018 23:10
notational aside: I'll be using haskell type notation for this, because that's what I'm comfy with....
Comfortable with Haskell.....
@RubberDuck Gotcha. I can imagine it'll help eliminate most dumb configurations. That said, ti was painful years when we got a server and it turn out it was all the wrong.
we can denote the types of the arguments a function f takes (and the type it returns) by using something like the following
f :: a -> b -> c -> d
f a b c = d
in a more "traditional" notation, that would be:
Check: -> => should call this function?
(I know nothing about Haskell)
function f(a a, b b, c c) As d
   return d
Mar 1, 2018 23:12
ah
sorry, one more thing to clarify
in math, we have notations like f(x)
or maybe f(x, y)
wouldn't it have been d = f(a, b, c) ?
@this if you'd go for math notation... yes
that's exactly what this boils down to.
[rubberduck-vba/Rubberduck] build for commit b20a7eb2 on next: AppVeyor build succeeded
now let's talk about delegates.
[rubberduck-vba/Rubberduck] build for commit b20a7eb2 on next: 55.76% (target 0%)
Mar 1, 2018 23:14
Consider a function: f :: x -> y (f(someX) = someY)
I guess what I'm not understanding yet why Haskell would write the function so that the last term is the return, and the terms in middle are the parameters --- do the parameters get passed into the function that they are called?
we can pass that function as an argument to another function
@this you're looking at the typedefinition there
oooh
@Vogel612 This is the type definition?
Where each argument is a function that takes a single argument.
Mar 1, 2018 23:15
so I'm defining the function, parameters and the return type in that first statement.
fun :: a -> b -> c -> d
fun someA someB someC = someD
----
Sub Fun(someA As A, someB As B, someC As C) As D
    Fun = someD
End Sub
OK
cool. back to how we can pass around functions.
let's say we have a function f.
f :: x -> y
f x = x^2
now if we want to use this as an argument in another function, we can denote that by enclosing the type in parens.
checking --- why isn't it written y = x^2
Mar 1, 2018 23:17
foo :: (x -> y) -> z
(i'm expecting the y to be the return type)
@this note that in the first line, x and y are type variables
in the second, they are values
OK.
might be better to use actual types for now....
f :: Double -> Double
f x = x^2
ah i see
so we're saying the function f will take a type of double, then return a double
then we define the function
Mar 1, 2018 23:18
correct
OK with you now
now we can pass f to another function. Something like map
... crap I need to introduce lists before introducing map...
well, lisps are lists. :)
Lists in haskell are denoted by square brackets around their typename.
Mar 1, 2018 23:19
... slower. Do a pow4
good idea.
okay. so we want a pow4
pow4 => raised to the 4th power, yes?
since we want to express that in terms of our f, it has the following signature:
pow4 :: (Double -> Double) -> Double -> Double
we can define it as follows:
is (Double -> Double) an anonymous function type?
Essentially. Yes.
Mar 1, 2018 23:22
pow4 square x = (square x) * (square x)
Hmm. interesting.
let me work that one out.
we have defined the body of the square x
that's the (square x) * (square x)
Just for context -> is right associative.
[rubberduck-vba/Rubberduck] build for commit 68dfa8ec on unknown branch: AppVeyor build succeeded
no that's the body of pow4. We don't even know the body of square right now, because square is a variable
> # [Codecov](https://codecov.io/gh/rubberduck-vba/Rubberduck/pull/3813?src=pr&el=h1) Report
> Merging [#3813](https://codecov.io/gh/rubberduck-vba/Rubberduck/pull/3813?src=pr&el=desc) into [next](https://codecov.io/gh/rubberduck-vba/Rubberduck/commit/b20a7eb2dbd62b6b48c05780a44671e16bcc0c48?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `51.43%`.


```diff
@@ Coverage Diff @@
## next #3813 +/- ##
=======================
[rubberduck-vba/Rubberduck] build for commit 68dfa8ec on unknown branch: 55.76% (target 0%)
Mar 1, 2018 23:24
that's the problem, actually. I was assuming that square x got defined because it was recursive
so I guess Haskell let you forward-declare the function square
@this you’re familiar with math, right? This is function composition.
f(g(x))
not that type of math, sorry, no. Last time I did math (years and years) I got as far as differntial equations and some fourier series but I've forgotten too much of it.
ah yes
yea. assuming that square is what it says on the tin, we can write pow4 as follows:
pow4 square x = square (square x)
I honestly don't remember having discussed stuff like right associative.
Right but we still do have to define the square in the haskell?
e.g. square x * x
for now it's just a variable
Mar 1, 2018 23:27
The confusing thing is that Haskell does not have the parentheses.
what you have there is something like this in C#:
double pow4(Func<double, double> square, double x)
{
    return square(square(x));
}
What I meant is that a -> b -> c -> d is the same as a -> (b -> (c -> d)).
@Vogel612 I feel like a chimp that's found the banana in the forest. I understand and follow!
@M.Doerner shh, you're spoiling the surprise
OK, but when you call the pow4, you do have to pass in the function definition.
Mar 1, 2018 23:29
well... yes.
so I'm still thinkin that in Haskell I have to actually define what a square is
And in general not the same as (a -> b) -> c -> d.
let's rename some of these things that we got:
night
the old f that we had. Let's call that square
Mar 1, 2018 23:30
night
the pow4 that we had, let's call that twice
writing it down, we have the following now:
square :: Double -> Double
square x = x * x

twice :: (Double -> Double) -> Double -> Double
twice f x = f(f(x))
I miss typevariables...
okay, now to the mindboggling part.
right.
this is making sense now
given these two function definitions: how would you write a function pow4?
wait wait
didn't we already have it?
that is, the twice is equivalent to pow4?
hum. no. That's a bit ... my fault
because... we have no clue what f is...
Mar 1, 2018 23:34
right.
add5 x = x + 5
add10 x = twice add5 x
so I have to define f I assume
lol I have no clue what the f is
no. you have to pass it as argument
wait wait, so fis a type?
Mar 1, 2018 23:35
no. it's a variable, that just happens to actually contain a function
drat
ok so f is equivalent to C#'s Func<...>
7 mins ago, by Vogel612
double pow4(Func<double, double> square, double x)
{
    return square(square(x));
}
which will return x
right
4 mins ago, by Vogel612
given these two function definitions: how would you write a function pow4?
just to make sure I'm following among....
f has the type of (Double -> Double)
Mar 1, 2018 23:37
correct
which is why we can then write f(f(x))
also correct
which amounts to "run the function f on the x, take the result then apply it to function f again"
@SlowLearner You're not entirely alone. I'm sorta following. But I have to think about it really hard for it to make sense.
Mar 1, 2018 23:38
that's where the name twice came from
Furthermore -
Just as a refresher.
https://chat.stackexchange.com/transcript/message/43158183#43158183
because we have twice :: (Double -> Double) -> Double -> Double
the 3rd Double is the input
that's what we've been using as the x in the body
Mar 1, 2018 23:39
I'll be bookmarking this, need to do some work
fully correct
This tweaks my brain more than a tad.
square :: Double -> Double
square x = x * x

twice :: (Double -> Double) -> Double -> Double
twice f x = f(f(x))

pow4 :: twice -> Double -> Double
pow4 x = twice(square(x))
?
good try, but not quite
square(x) returns a Double
twice expects a Func<Double, Double> as it's first argument...
I see
wait wait
Mar 1, 2018 23:43
=)
can't i say that square is a Func<double, double>
More than just say it. It is.
@IvenBach BrainBreaker.hs WARNING, contains major spoilers
not looking
pow4 :: twice(square) -> Double -> Double
pow4 x = twice(square(x))
?
now you're mixing types with variables...
Mar 1, 2018 23:45
I looked but aren't trying hard enough to cumprehendrize... Brn mltng fm hrd thkng...
ah right.
actually you did that before as well ...
ok, so recaping for myself....
it's not really much help, but pow4 :: Double -> Double
i'm declaring a new type square :: Double -> Double
Mar 1, 2018 23:46
I'll interject when it's wrong, okay?
OK.
I then define the body of the function type
which is the square x = x * x
Just to be sure, the first term on the left side represents the result, which corresponds to the last argument from the function type definition.
actually the second term (the first x )
the left side is the function name, followed by the argument list.
rephrasing a bit more --- the x on the left-side will have the type of the last term in the definition.
Mar 1, 2018 23:48
the = is basically the opening brace, return is implicit
then i do not understand why we write square x to the left
that's part of the "method header"
why not simply square = x * x
what is the significance of the x to LHS of the =?
> I'm assuming these aren't exported along with the source code when using the "Export All" feature?
We've remove git integration (#3758), but the export feature is still there.

Would you like us to reword this request to "Export all exports Ribbon XML files"?
foo :: TypeArgument1 -> TypeArgument2 -> TypeResult
foo bar baz = something
---
TypeResult foo(TypeArgument1 bar, TypeArgument2 baz) {
    return something;
}
@this because then x is not defined
@this x on the LHS is the parameter declaration
Confirming.... if I define: bar :: foo1 -> foo2 -> foo3 -> foo4 -> foo5
that's 5 different types
and therefore in the definition, i must assign names for each parameter
so therefore bar parameter1 parameter2 parameter3 parameter4 = <body of the function>
?
not quite... foo5 is the return type
Mar 1, 2018 23:53
oops
better?
@this let's say yes for now.
ok.
Mar 1, 2018 23:53
@this yes, better
point being the return type is implicit
no it's not. it's foo5
i was referring to the definition, not the declaration
Mar 1, 2018 23:55
I'm pretty sure that the words you use are wrong, but you mean the right thing, then
OK
ok, back to the pow4 project.
concept check
square :: Double -> Double
square x = x * x
therefore, the first x is the actual name of the variable that represents the input Double
:+1:
Then the body to RHS of the = tells what we will do with the named variables
Mar 1, 2018 23:56
yes
> Gagh! This is very much what I imagined early on....
Oh well. That is life.

We decided in #3758 to remove the feature.
the = was throwing me off here. Good to get that clarified.
It's kind of like this c# lambda.

square(x) => x * x
In Haskell.
square x = x * x
yeah
ok, just to confirm -
is it legal to use terms like so....
@RubberDuck let's make this a syntactically correct var square = (x => x * x);
Mar 1, 2018 23:59
pow4 :: twice -> Double -> Double
e.g. I used the twice as a type here
@this no, that doesn't work
twice is not a type
it's a name
so even though I've defined twice :: (Double -> Double) -> Double -> Double
which is a function
I can't use it like a type,.
these function definitions are basically constants.
OK,
RELOAD!
[Hosch250/CheckersTreasury] 1 commit. 108 additions. 1194 deletions.
[rubberduck-vba/Rubberduck] 12 commits. 3 opened issues. 6 closed issues. 38 issue comments. 1178 additions. 1038 deletions.
> @retailcoder still seems like a valid feature request, even in light of #3758. Thoughts?
Mar 2, 2018 00:01
you can't say public double pow4(twice f, double x), you'd theoretically need a typeof
hmm i'm going to feel silly if that's right but does that imply that I shold have written pow4 like so.... pow4 :: ((Double -> Double) -> Double) -> Double
aw! I need to go now. :( I really want to solve. But I must go now. #IWillBeRightBack
@this well, that would match more closely the definition of what you tried to express, yes
one possible valid definition of pow4 is the following:
pow4 :: Double -> Double
pow4 x = x * x * x * x
but that'd be boring and not really functional.
let's try if we can simplify this.
something a bit simpler would be the following:
pow4 x = (square(x)) * (square(x))
and here's where I leave you, because I have a reading date with my GF and I'm pretty sure with some thought you should be able to connect the remaining dots
 
Conversation ended Mar 2, 2018 at 0:05.