How to implement a language using a functional language? [closed] - haskell

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I prefer Haskell.
I already know How to create my own language with Procedural Language (for example: C, Java, Python, etc).
But, I know How to create my own language with Functional Language (for example Haskell, Clojure and Scala).
I've already read:
Internet Resources
Write Yourself a Scheme in 48 Hours
Real World Haskell - Chapter 16.Using Persec
Writing A Lisp Interpreter In Haskell
Parsec, a fast combinator parser
Implementing functional languages: a tutorial
Books
Introduction Functional Programming Using Haskell 2nd Edition -- Haskell
StackOverflow (but with procedural language)
Learning to write a compiler
create my own programming language
Source
Libraries and tools/HJS -- Haskell
Are there any other good links/sources? I would like to get some more.

Programming Languages: Application and Interpretation is frequently used in programming language classes, and is available online for free. It uses Scheme.
Types and Programming Languages is another incredible book dealing with type systems (including implementation), though only available in dead tree format. It uses ML (which represents a significant family of functional languages that I noticed was missing from your list).
Racket (formerly called PLT Scheme) is a functional language that emphasizes making your own sub-language.

read also:
Christian Queinnec's Lisp In Small Pieces book,
Andrew Appel's Compile with Continuations (and also his book Modern compiler implementation in ML isbn:0521582741)
I also think that Jacques Pitrat's latest book Artificial Beings - the conscience of a conscious machine will give you very interesting insights.

Take also a look at Compiler.HOOPL and Control.Unification libraries, and uuagc attribute grammar preprocessor. You also can read https://wiki.ittc.ku.edu/lambda/images/e/e3/Modular-interpreters.pdf on writing modular interpreters in Haskell. Also note that Parsec is not very fast and for non-toy projects Happy/Alex may be suited better.

Related

What functional language approach most readily transfers to Boost Phoenix? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am looking to learn functional programming with an am to integrate Boost.phoenix into my project.
What language is most similar so that I can find books that will illustrate functional programming concepts in a way that can be readily applies in that context... Are haskell and ocaml similar?
ALternately are there any good functional programming books written in general terms that can be applied to Boost.phoenix?
Phoenix enables functional programming (FP) in C++. Consequently, the language that will be most synergistic is going to be C++.
If you want to learn functional programming on its own terms, languages like Haskell and Scheme may be better choices.
http://www.boost.org/doc/libs/1_51_0/libs/phoenix/doc/html/index.html
I don't have any experience with Phoenix (I've skimmed the docs), but I do have some with C++, OCaml, and Haskell so I may be able to help there.
First off, if you learn functional programming you'll find it doesn't translate prettily to C++ - it ends up messier and more verbose than if done in an actual functional language. Nevertheless, it is still worth learning the techniques as they will give you more tools and a different mindset.
Are haskell and ocaml similar?
They are both influenced by ML so they are quite similiar (well, sorta, see the comments). OCaml is closer to C++ because of it's imperative and OO features, but I recommend you learn Haskell as it is more functional, more mindbending, and has more resources. An interesting thing about ML-like languages that they translate quite nicely to template metaprogramming.
ALternately are there any good functional programming books written in general terms that can be applied to Boost.phoenix?
The docs of Phoenix seem to use fairly standard terms. The one thing which could be confusing is their use of the word 'functor' - in C++ it means function object but in languages like Haskell it is something else.
Here are a few terms that you should look for:
lambda / anonymous function
first class function
function application
partial application and currying
composition
strict/non-strict/lazy evaluation
recursion
closures
Here are two free books which I recommend reading as they are a great introduction to functional programming:
http://learnyouahaskell.com/chapters (Haskell)
http://mitpress.mit.edu/sicp/full-text/book/book.html (Scheme)
I don't know much about Phoenix but I think that Okasaki's Purely Functional Data Structures can give you more or less general look how to write programs in functional style.

Is it true that Lisp is not a functional programming language? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I read in the book: "Masterminds of programming" , the the interview with Guido Van Rossum says:
The more fundamental property Python shares with Lisp ( not a functional language either! ) is that functionas are first-class objects...
So, Lisp is not a functional programming language?
Is Guido wrong? What is it then?
Pretty much every Lisp I know of can be used to program in a functional style (all you really need are first-class functions, after all!)
However, Lisps are more like multi-language toolkits: you can do functional programming, OOP, logic programming, define your own DSL for some whacky new paradigm etc.
The Lisp that is probably closest to a functional programming style is Clojure (it has lazy evaluation, discourages OOP, uses immutable data structures throughout, restricts uncontrolled mutation (via STM), has quite a lot of pure / higher order functions in the core library etc.)
There are languages that allow and encourage functional programming paradigms. Both Python and Lisp are among these. Lisp in particular was the first one to apply theoretical concepts derived from lambda calculus. In the late 1950s, when almost only FORTRAN and Lisp existed, Lisp was highlighted as the functional one, where FORTRAN, with a fully static memory management, would never be considered functional.
However, neither Python nor Lisp enforce pure functionality, allowing mutable variables, states and imperative constructs. A mixture of styles can always be handy in practice, so probably you will not find many example of pure concepts in very successful tools.
Among purely functional languages, Haskell, Clean and Miranda are listed examples, but I cannot say anything about them.

LISP or Haskell [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 12 years ago.
LISP or Haskell, I need to learn functional programming, but I heard that lisp is very old, any advice between those two languages ?
Just to echo the others, I'd learn both Scheme (a more functional Lisp dialect) and Haskell. Scheme / Lisp have some useful tricks to teach you about 'code is data / data is code' and macros. Scheme encourages a good functional style and I would recommend the 'The Little Schemer' series of books to get you started on this. SICP is also a fantastic text http://mitpress.mit.edu/sicp/full-text/book/book.html and possibly one of the best books ever written on programming. Scheme is more accessible as a first functional language.
Once you've got the hang of Scheme you'll probably find yourself becoming frustrated with the lack of libraries, lack of parallelism and the small, although excellent, community. This is where I was when I decided to learn Haskell. Haskell is very mature, very useful and very functional and it is quite a challenge to learn once you move off the basics and so having a grounding in another functional language will help enormously. You won't regret learning either (or both).
Why not both? LISP is very easy to learn (I'd go for the Scheme dialect - see http://racket-lang.org) so I'd start with that. If you like it, stick with it, but I'd also give Haskell a go, although it is (in my experience) considerably harder to wrap your head around.
The great thing about computing these days is that you can try all these languages for free, apart from your time. When I started programming LISP was only available on mainframes, which put a bit of a crimp on trying to learn it.
Haskell, because once you've learned Haskell, you will love it. And then, you will be able to learn Common LISP. However, if your editor is Emacs, then go start with Lisp.
If you want to learn functional programming through implementing a compiler or interpreter of a language, then Lisp or ML should be a better first choice as they're much simpler to implement than a lazy language. Otherwise you'd better learn both.
Choosing based on age is silly, Haskell has been around much longer than say C# and its history extends back a lot further. Anyway I'd recommend learning both eventually, for learning functional programming, Haskell is specifically about purely functional programming (in a number of senses of the meaning). Scheme is a functional orientated descendant of lisp.

As an EE/CE, what languages/concepts should I become more familiar with before graduating? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am currently entering my senior year as a dual major in Electrical Engineering and Computer Engineering, and have touched on a wide variety of different languages: C, C++, C#/XAML, Java, bash, python, VHDL, assembly, etc. I was wondering what you think would be a good language/few languages to become more proficient in, or to explore for a first time. Also, what level of programming you prefer (hardware, local, network, system, design, integration, and so on) If you could tell me why, I would be grateful, or if you'd like to relate your experiences, I am quite interested
. I am hoping to find a job in hardware design, but as I become better with some languages, I am finding just how much I enjoy programming, so I really have an open mind at this juncture. I would love to hear from some people in the 'real world'.
You want to understand:
Different language paradigms (procedural, oop, functional, parallel, logic [e.g., Prolog], constraint). Do some programming in each.
Different software architectures. OSes, standard applications (MVC, ...)
Software Engineering: requirements, specifation (especially design-by-contract), design, testing. These ideas hold in hardware engineering too.
I would start not by learning a programming language but the fundementals like below 1) computer organisation 2) operating systems theory 3) fundementals of programming (oop and functional) 4) data structures 5) Compiler design and principles 6) dbms concepts
As a budding hardware designer you might want to learn Bluespec. This is a very high-level hardware-description language based on work done at MIT. It's both a language and a company. They have some very impressive results on modularity, predictability, and reuse in hardware design. Check out the page on the Bluespec compiler and find out if you want to pursue it.
I was wondering what you think would be a good language/few languages to become more proficient in, or to explore for a first time?
What do you want to accomplish? You seem to have a good grasp of many popular languages with several typing systems and paradigms. If you want to learn something else new, I would recommend functional programming as it's vastly different from anything you will have encountered before (imagine trying to write a program without an assignment operator eg. =) and becoming more and more useful. Haskell, Scala, and F# are all forerunners of the functional programming pack.
Also, what level of programming you prefer?
It all depends on what you want to do and what skills you want to use. Hardware and system programming will involve more low level stuff (assem, C, C++). The others are less language specific, but involve other skills, like a thorough knowledge of networks and APIs.

Language to learn metaprogramming [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 12 years ago.
What's the best language (in terms of simplicity, readability and code elegancy) in your opinion, to learn and work with metaprogramming?
I think metaprogramming is the "future of coding". Not saying that code will extinct, but we can see this scenario coming on new technologies.
First -- I don't think I agree with your claim that "metaprogramming is the 'future of coding'". It's a great tool, but not everybody likes it (for example, the Java designers left macros out of the language intentionally -- not that I like Java, but people do have reasons to object to metaprogramming).
Anyway...
I can think of two different ways of doing metaprogramming: on the syntatic level and at runtime.
For syntax metaprogramming, I think Scheme is a good option (if you hadn't mentioned simplicity etc I'd suggest Common Lisp).
For runtime metaprogramming I guess both Prolog and Smalltalk are very interesting. (You can add, change and remove facts to a Prolog database on the fly; and you can change Smalltalk objects on the fly to). You can probably do runtime metaprogramming in Ruby too, but I don't know Ruby.
So --there are several different metaprogramming methods in Scheme (different macro systems). I suggest you take a look at some basic Scheme book and later read about two different macro systems.
Some good Scheme books:
Simply Scheme
Teach Yourself Scheme
Structure and Interpretation of Computer Programs
Scheme implementations are very different from each other, so you'll also use your Scheme implementation manual a lot too.
Some places to learn about Scheme macros:
http://www.lispforum.com/viewtopic.php?f=22&t=100
http://www.ibm.com/developerworks/linux/library/l-metaprog2.html
http://chicken.wiki.br/explicit-renaming-macros
If you decide to use a language that's larger and messier than Scheme, try Common Lisp. There are three books that I'd suggest:
First, "Practical Common Lisp" by Peter seibel. That will get you started on Common Lisp and macros;
Second, "On Lisp" by Paul Graham. You'll then learn that macros are more powerful than what you had thought before, and will learn really nice techniques;
Third, "Let Over Lambda" by Doug Hoyte. An advanced book, best read after Graham's On Lisp.
For Prolog, you can read "Programming in Prolog" by Clocksin and Mellish (get the latest edition!) and later move on to "Prolog Programing in Depth" by Covington, Vellino and Nute. See chapter 6.
There are lots of good Smalltalk books. I like "The Art and Science of Smalltalk" by Simon Lewis.
There's a very nice free tutorial/primer by Canol Gokel about Smalltalk too (but it doesn't go as far as teaching metaprogramming).
What do you mean by metaprogramming? Metaprogramming is a set of concepts, rather than one specific technique.
See this answer where I've listed various concepts and related languages. Here is a summary:
Metaprogramming with macro --> Lisp
Metaprogramming with DSL --> Many languages for internal DSL, external DSL is more tricky
Reflection --> Smalltalk, Ruby
Annotations --> Java
Byte-code or AST transformation --> Groovy
See the complete answer for more details. Generally speaking, I think that a good OO all-rounder is Ruby. Otherwise any Lisp-like is will do the job: it's like putty in your hands. But that will depend on what you want to do...
The Lisps are pretty much the language of choice for a wide variety of metaprogramming techniques. Of the modern Lisps available, I would recommend Clojure as a more accessible Lisp that has access to a positively HUGE library (anything in Java land) if you want something that is both powerful and immediately useful.
For other approaches to metaprogramming almost any functional language will do the trick. Haskell is a good choice for learning techniques and functional programming but isn't what I'd call the most practical language to do real work in at this time. Erlang is more practical, but not quite as amenable to metaprogramming. OCaml is another possible choice but suffers a bit on the practicality front as well. It is more accessible than Haskell in many regards, however.
In the scripting language world Ruby is a language in which metaprogramming is a popular technique. Its approach is vaguely Lisp-like, but with a far more conventional syntax. It lacks the full power and flexibility of the Lisps, however, but on the other hand, with the exception of Clojure above, it has a lot more immediate practical utility.
Ruby has very powerful and flexible metaprogramming capabilities.
There are several languages that I would recommend for studying meta-programing.
The first is Prolog. A Prolog program is a database. Prolog "code", the clauses, are part of the data. The program can read them, including their content. It can also generate new code as a data structure and assert it, thus changing itself on run-time. All of this without using term expansion, which is Prolog's smart macros system. Some Prolog AI books start with implementing a meta-interpreter in Prolog, and then changing it by need.
The second is, as mentioned, Lisp, and particularly CLOS (Common List Object System), which includes commands for meta-OOP.
Finally, Python support a nice and not too obscure mechanism for run-time meta-programming, which is it's meta-classes (classes that create classes).
I'm surprised no one has mentioned ML. ML stands for Meta Language. so... yeah... CaML is a standard implementation. (OCaML, which JUST MY correct OPINIO mentioned is the OO version of CaML, which probably adds features that make the meta-programming less obvious...)
Other than that, I am a big fan of Scheme, but pretty much any Functional programming language is good for this... There's always the Little Lisper, er, sorry, the Little Schemer...
Don't know if we have the same definition of "meta programming" but there is certainly not ONE best language to learn. I would propose that you have a deeper look at functional programming. Which language to choose for that depends on your background and working environment. I would choose F# at the moment, but Haskel should also be a good choice.
cheers,
Achim

Resources