News for hackers. Stuff that matters.
Re:The Evolution of a Haskell Programmer (2001) by cageface on Monday February 08, 2016 @06:21PM (#11061735)
I don't think Haskell will ever become mainstream but concepts that originated in research languages like Haskell are increasingly common in more pragmatic mainstream languages. Swift owes a lot to the ML & Haskell family of languages, for example, and even C++ and Java have lambdas now.
Re:The Evolution of a Haskell Programmer (2001) by DonaldFisk on Monday February 08, 2016 @07:54PM (#11062221)
... which Lisp had in 1960.
Re:The Evolution of a Haskell Programmer (2001) by such_a_casual on Monday February 08, 2016 @09:04PM (#11062545)
When I look at some of the fundamental differences between lisp and the mainstream languages (like everything-as-expressions and explicit scoping of variables and functions), I realize that Lisp is centuries ahead of its time. How long is it going to take mainstream languages to implement explicit scoping like let and flet? 75 years after lisp was born? How long for everything-as-expressions (which gives code a logical structure and eliminates the need for throwaway variables)? 100 years? 200 years? Will we even have programming languages by then?
Re:The Evolution of a Haskell Programmer (2001) by omaranto on Monday February 08, 2016 @11:34PM (#11063085)
Ruby counts as mainstream, right? It is expression based.
Re:The Evolution of a Haskell Programmer (2001) by dllthomas on Tuesday February 09, 2016 @12:24AM (#11063298)
> explicit scoping like let and flet?

I'm not sure how this is different than introducing a block in C.

Re:The Evolution of a Haskell Programmer (2001) by such_a_casual on Wednesday February 10, 2016 @04:28PM (#11076164)
I haven't programmed in C, but my view comes from this video: https://www.youtube.com/watch?v=QM1iUe6IofM&feature=youtu.be...

What would be the C equivalent of:

    (let ((last-response))
      (defun get-response ()
        (print last-response)
        (setf last-response (read)))) 
    
    (print (get-response))
    (print (get-response))
Notice that no other function can use last-response. It only exists for get-response, but it exists outside the scope of get-response. Does C have this?
Re:The Evolution of a Haskell Programmer (2001) by dllthomas on Wednesday February 10, 2016 @08:18PM (#11077603)
As used here, there's two ways you can do this in C.

Since the variable in question is only used in one function, you could declare the variable static to that function. It takes some care to make this reentrant, but that's possibly the case in lisp as well.

To share between multiple top-level functions, you can only limit scope to the individual file.

The bigger thing C can't do that lisp can here is defining new functions in arbitrary places. In C variants where you can define local functions, you can indeed capture variables in local scope. And within a function, you can limit scope by creating a new block:

    int test() {
        int foo = 7;

        {
            int foo = 9;
        }

        return foo; // returns 7
    }

Even in those C variants, you can't place a new function in global scope from within a function.
Re:The Evolution of a Haskell Programmer (2001) by such_a_casual on Wednesday February 10, 2016 @10:09PM (#11077990)
I did not know C had static variables at the function level (thank you for pointing this out), but static variables are not the same thing as what I'm thinking of when I say "explicit scoping". It would basically be like writing curly braces for variable declarations the same way one does with function definitions. Because lisp has this it's trivial to extend the scope of the variable to cover multiple functions:

    (let ((x))
      (defun func1 ())
      (defun func2 ()))

This is what I mean when I say explicit scoping. And it means that the reader/debugger/maintainer knows that this variable only exists for these functions. A static variable's scope is implied by the scope of whatever it's defined in (not sure if that's limited to functions in C), in this case X exists outside of C and has it's own scope, not just it's own extent.
Re:The Evolution of a Haskell Programmer (2001) by dllthomas on Thursday February 11, 2016 @01:01AM (#11078483)
"Because lisp has this it's trivial to extend the scope of the variable to cover multiple functions:"

Yes, I mentioned that static variables in a function would not extend to multiple functions.

You can share a variable between a restricted set of top level functions by grouping those functions in a single object file that does not expose the variable in question.

I think my only objection is that your phrasing implied what's different is the explicitness of the scoping, when it's actually the flexibility of how functions can be defined (unsurprising, from a lisp).

Re:The Evolution of a Haskell Programmer (2001) by such_a_casual on Friday February 12, 2016 @02:15AM (#11085754)
I used the word explicit because I was thinking something along the lines of: the scope in lisp is explicitly defined with parentheses (). Where as something like a static variable (or pretty much any variable that's defined in Algol like languages) has implicit scoping, it's implied that it shares the same scope as the scope it's defined in (or some other implication like C#'s public). I'll have to find a better way to word it because you're right. Thank you for the discussion.