These are chat archives for ramda/ramda

7th
May 2015
Raine Virta
@raine
May 07 2015 08:20
how do you denote a function that takes no arguments in haskell style notation?
Scott Sauyet
@CrossEye
May 07 2015 10:57
Haskell itself would probably never deign to consider such a travesty. In our bastardizaton of that syntax, I would probably use 'void' or '()' or perhaps '_'.
Simon Friis Vindum
@paldepind
May 07 2015 11:03
@raine @CrossEye It wouldn't make any sense would it? A pure function with no arguments is just a constant.
And with Haskell syntax there is no syntax difference between naming a constant and "invoking" a function with no arguments.
Raine Virta
@raine
May 07 2015 11:07
I have a function that takes no arguments and returns a promise
(in javascript) - perhaps in a lazy language the call would be superfluous?
Simon Friis Vindum
@paldepind
May 07 2015 11:47
Well, I certainly makes sense in JavaScript! I have no idea what it would be in a functional language.
Michael Hurley
@buzzdecafe
May 07 2015 14:26
Makes sense in scheme too. As you said, it is essentially a constant function (lambda () 1)
Hardy Jones
@joneshf
May 07 2015 15:39
@raine Yeah, in haskell the non-strictness takes care of it. You can pass it around, give it as an argument, return it from a function, unless someone actually uses the argument it won't be evaluated.

for instance:

λ: const 3 (1 `div` 0)
3
λ: const (1 `div` 0) 3
*** Exception: divide by zero

Since const doesn't evaluate its second argument, no exception is raised when you divide by 0 in the second argument. But when you divide by 0 in the first argument, an exception is raised, as const evaluates its first argument.

of course, if you force the second argument, the exception is raised:
λ: const 3 $! (1 `div` 0)
*** Exception: divide by zero
Hardy Jones
@joneshf
May 07 2015 18:24

actually, that's still not entirely true...

ghci is doing the evaluation there, forcing the Show instance. It has nothing to do with how const is implemented. The function doesn't force either argument. But ghci wanting to show the result does force the return value. So something like this, still doesn't raise an exception:

λ: const 3 (const (1 `div` 0) (0 `div` 0))
3

Even though the nested const has both exception raising arguments, it doesn't matter as the value is never forced.

Raine Virta
@raine
May 07 2015 18:28
naming things, such impossible
Viktor Fröberg
@vikfroberg
May 07 2015 21:45
@raine Thanks!