Are all the built in functions of a programming language made up of the primitives? - programming-languages

I know, I can define new functions with the help of the primitives that the language provides me, but I want to know if the built-in functions are also defined by the same primitives or there is something else that powers these functions?

Often, yes. In many cases, the libraries provided are implementations of the language's given primitives, and someone has made various functions out of them to make your life easier.

Related

Are there other HOL programming languages besides Caledon that are based on haskell?

There are programming languages and theorem prover based on higher order logic (HOL). Examples include Twelf, lambda prolog, Isabelle. For example Twelf is is both a programming language and a theorem prover, while Isabelle is mainly a theorem prover, but for Isabelle code extraction is available.
I am looking for a HOL programming language based on haskell. The reason is that I like, for instance, lambda prolog very much, but it is not meant as a practical programming language. Lambda prolog lacks a standard library and interfacing with external libraries doesn't seem trivial. The problem is if you need some functionality, like writing a parser for a text file, you can't interface, say, with the many available existing libraries for haskell, and further, there is no standard library so you start from scratch.
Today I came across the Caledon programming language that was implemented as a master thesis, it seems. From the github page:
Caledon is a dependently typed, polymorphic, higher order logic
programming language.
This is interesting, since it is written in haskell so it should be easy to extend and interface with existing haskell libraries. But it seems that the project is in a bit early stage, I am not sure if input-output (IO) is implemented. Since I learned only today about Caledon, I think I might have missed some further projects. (BTW, I am not interested in standard logic programming languages like prolog).
Are there programming languages based on higher order logic besides Caledon that are implemented in haskell?
(I am asking for "implemented in haskell", as it is rather easy to connect programming languages that can be extracted to or are implemented in haskell. For example the Agda programming language can compile to haskell code and haskell libraries can be used conveniently and is extremly easy to use haskell libraries if you know how. Many other programming languages (e.g., ATS) I belive only provide the smallest common denominator which is a C based foreign function interface (FFI). In my eyes it is quite cumbersome to connect two higher programming languages via their respective C-based FFI interface. Thus the seemly abitrary part that "it should be implemented in haskell". Further, as a side note some users have downvoted in the past for my description of Agda as a programming language, but of course this is not true, i.e., consider Curry-Howard )
"Haskabelle is a converter from Haskell source files to Isabelle/HOL theories implemented in Haskell itself."
Haskabelle
Strange Statement: Haskell' is a higher order logic programming language based on Haskell. Type inference in Haskell with multiparameter type classes, type families, undecidable inference and whatnot actually forms a higher order logic programming language. This probably doesn't help you very much because:
The spec is literally constantly changing (I've had a few packages loose compatibility as they were based on hacks that got "fixed")
The type system itself doesn't have IO (yet?)
It can't really call other Haskell libraries from type inference
Its not very fast.
The logic programming semantics aren't exactly clear or stable.
It doesn't permit you to unify with lambdas or other type classes, although it does permit unification with functions.
Sadly, I know of extraordinarily few full HOL languages let alone ones implemented in Haskell - it turns out higher order unification is a huge pain to implement.
short answer: i don't know. long answer: you have small chances you will find purely academic language with thousands of libraries and tools for it. if you for some reason need that specific language for some specific problem then use it ONLY for that problem. not for parsing files, calculating taxes or launching rockets. create library and link it with other programs. or even better: create a microservice or connect the programs in other way (e.g. standard input/output) that doesn't require much effort. always use best tool for the job

Haskell, FFI, and Grand Central Dispatch?

I'm considering a functional language that will play well with my environment of C/Objective-C under FreeBSD, OSX, iOS. It looks like my best bet is to create functional-language libraries for specific functions, written in Haskell, compile with GHC, and use FFI to call this functional code as a standard C call.
My question is, how do I handle concurrency in this situation? One motivation for using a functional language is that for my problems where I want to operate on immutable datasets, I want to get a lot of parallelization going. However, using the approach I detail here, will I get ANY parallelization? It appears I can compile and dictate to use 2 threads, but is there any way to use GCD instead of threading (for all the reasons GCD is better than threads, such as the amount of parallelization automatically scaling per-platform)? Or, going with FFI as I describe, do I completely lose the ability to multithread?
This language seems like the best match for what I'm trying to do, but I want to learn if it's the right fit before I devote a significant amount of time to truly learn it
GHC's runtime replaces the need for GCD, doesn't it? And it already provides cross-platform parallelism.

Distinctive characteristics of programming languages [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.
Beyond the syntax of each language (e.g. print v. echo), what are some key distinctive characteristics to look out for to distinguish a programming language?
As a beginner in programming, I'm still confused between the strengths and weaknesses of each programming language and how to distinguish them beyond their aliases for common native functions. I think it's much easier to classify languages based on a set of distinctive characterstics e.g. OOP v. Functional.
There are many thing that define a PL, here I'l list a few:
Is it procedural, OO, imperative?
Does it has strong type checking(C#, C++, Delphi) or dynamic(PHP, Pythong, JS)
How are references handled? (Does it hide pointers like C#?)
Does it require a runtime (C#, Java) or is it native to the OS(C, C++)
Does it support threads (E.g Eiffel needs extra libraries for it)
There are may others like the prescense of garbage collectors, the handling of params, etc. The Eiffel language has an interesting feature which is Design By Contract, I haven't seen this on any other language(I think C# 4.0 has it now), but it can be pretty useful if well used.
I would recommend you to take a look on Bertrand Meyer's work to get a deeper understanding on how PL's work and the things that define them. Another thing that can define a PL is the interaction level with the system, this what makes the difference between low-level languages and high-level languages.
Hope I can help
In a domain (imperative, functional, concatenative, term rewriting), sometimes its best to look at the presence or absence of any particular set of functionality. For example, for the main stream imperative.
First order functions
Closures
Built in classes, prototypical inheritance, or toolkit (Example: C++, Self/JavaScript, Lua/Perl)
Complex data types (more than array)
In-built concurrency primitives
Futures
Pass by values, pass by name, pass by reference or an combination thereof
Garbage collected or not? What kind?
Event-based
Interface based types, class based types, or no user types (Go, Java, Lua)
etc
You can consider things like:
Can you call functions?
Can you pass functions to other functions?
Can you create new functions? (In C you can pass function pointers to functions, but you cannot create new functions)
Can you create new data types?
Can you create new data types with functions that operate on them? (the typical basis for "OO" languages)
Can you execute code that was not available at compile-time (using an eval function, maybe)?
Must all types be known at compile-time?
Are types available at run-time?
The difference between low-level and high-level languages. (Even though "low" and "high" are relative terms.)
A high-level language will use an abstraction to hide details that low-level languages would expose to the user. For example, in Matlab or Python, you can initialize an N-dimensional array in a single command. Not so in C or assembly.
IMHO the strength of a language is given by how many things you can do with it; how fast and how easy can you accomplish the goals.
The weaknesses of a language are the sum of constraints (of various types) that you encounter while you try to achieve your goal.
There are many features that a programming language may support. Additionally these features aren't always mutually exclusive. For example OCaml and F# are both functional and object oriented. Also writing a list here of all the paradigms that a language can support would be exhaustive, however there is a book Programming Language Pragmatics that is a comprehensive treatment of many paradigms found in programming languages.
However, for me the important things I need to know when working with a language are the following:
Is it dynamically or statically typed
Is it a typed language, and if it is typed is strong or weak?
Is it garbage collected
Does it support pass by value or pass by reference semantics or both?
Does it support first order functions (i.e. can functions be treated as variables)
Is it object-oriented
Polymorphism. Is it parametric or ad-hoc.
How expressive is the type system (i.e. can I create non-leaky abstractions)
Overloaded methods
Generics (templates)
Exception handling.
Type system (typed vs untyped, statically vs dynamically typed, weakly and strongly typed).
Supported paradigms (procedural, object-oriented, functional, logic, multi).
Default implementation (compiler vs interpreter vs JIT-compiler).
Memory management (manual vs automatic (reference counting or GC)).
Intended domain of use (number crunching, prototyping, scripting, DSL, ...).
Generation (1GL, 2GL, 3GL, 4GL, 5GL).
Used natural language (English vs Non-English-based). However, it's about syntax.
General remark: many of this classification scheme are not comprehensive and are not that good. And links are mostly at Wikipedia. So be aware.
You can consider other characteristics such as:
Strong vs weak and static vs dynamic typing, support for generic typing
How memory is handled (is it abstracted or do you have direct control over your data, pass by ref vs pass by value)
Compiled vs interpreted vs a bit of both
The forms of user-defined types available... classes, structures, tuples, lists etc.
Whether threading facilities are inbuilt or you need to turn to external libraries
Facility for generative coding... C++ template metaprogramming is a form of this
In the case of OOP, single vs multi inheritance, interfaces, anonymous/inner classes etc.
Whether a language is multi-paradigm (i.e. C# and its support for functional programming)
Availability of reflection
The verbosity of a language or the amount of 'syntactic sugar'... e.g. C++ is quite verbose when it comes to iterating over a vector. Java is quite succinct when anonymous inner classes are used for event-handling. Python's list comprehensions save a lot of typing.

How many oo-functional hybrids are there?

We're discussing oo-functional hybrids here, but I wonder, how many languages actually qualify for this name. Scala, Clojure, F#? Any more?
It'd be great to get one such language per answer, and a little explanation, why you think it is oo-functional hybrid.
Objective Caml - as functional as any language from ML family is, but as the name implies, also has a well-developed (and somewhat unique - the only fully structural one I'm aware of) OO system.
Common Lisp. The functional aspects are quite evident, and, on the other hand, CLOS is the mother of all object models.
Smalltalk. I'm sure many will disagree, but I think that the language that not only had first-class functions, but used them so heavily that even the most fundamental constructs (such as if/else and loops) were implemented as function calls taking function-type arguments, deserves the label "functional". Besides, you list Ruby, and most of what it has in FP department, it inherited from Smalltalk.
Nemerle is (unfortunately) not so widely known functional-OO hybrid designed to run on the .NET platform. What makes Nemerle interesting is its versatile macro system and powerful type inference.
O'Haskell, which is basically a Haskell with object-oriented features bolted on.
Racket is a functional language (a dialect of Scheme) with an class system. The class system supports both overridable methods (like Java, C#) and augmentable methods (the superclass's method gets control first; it decides if/when to call the subclass's method and what to do with the result). The class system also supports higher-order contracts.
Actually, there are many object systems for Lisps and Schemes. CLOS for Common Lisp is probably the most famous and influential.

What languages implement features from functional programming?

Lisp developed a set of interesting language features quite early on in the academic world, but most of them never caught on in production environments.
Some languages, like JavaScript, adapted basic features like garbage collection and lexical closures, but all the stuff that might actually change how you write programs on a large scale, like powerful macros, the code-as-data thing and custom control structures, only seems to propagate within other functional languages, none of which are practical to use for non-trivial projects.
The functional programming community also came up with a lot of other interesting ideas (apart from functional programming itself), like referential transparency, generalised case-expressions (ie, pattern-matching, not crippled like C/C# switches) and curried functions, which seem obviously useful in regular programming and should be easy to integrate with existing programming practice, but for some reason seem to be stuck in the academic world forever.
Why do these features have such a hard time getting adopted? Are there any modern, practical languages that actually learn from Lisp instead of half-assedly copying "first class functions", or is there an inherent conflict that makes this impossible?
Are there any modern, practical
languages that actually learn from
Lisp instead of half-assedly copying
"first class functions", or is there
an inherent conflict that makes this
impossible?
Why aren't lisp, haskell, ocaml, or f# modern?
You might just need to take it on yourself and look at them and realize that they are more robust, with libraries like java, then you'd think.
A lot of features have been adopted from functional languages to other languages. But vice versa -- (some) functional languages have objects, for example.
I suggest you try Clojure. Syntactically beautiful dialect, functional (in the ML sense), and fast. You get immutability, software transactional memory, multiversion concurrency control, a REPL, SLIME support, and an inexhaustible FFI. It's the Lisp (& Haskell) for the Business Programmer. I'm having a great time using it daily in my real job.
There is no known correlation between a language "catching on" and whether or not is has powerful, well researched, well designed features.
A lot has been said on the subject. It exists all over the place in technology, and also the arts. We know artist A has more training and produces works of greater breadth and depth than artist B, yet artist B is far more successful in the marketplace. Is it because there's a zeitgeist? Is is because artist B has better marketing? Is it because most people won't take the time to understand artist A? Maybe artist B is secretly awful and we should mistrust experts who make judgements about artists? Probably all of the above, to some degree or another.
This drives people who study the arts, and people who study programming languages, crazy.
Scala is a cool functional/OO language with pattern matching, first class functions, and the like. It has the advantage of compiling to Java bytecode and inter-operates well with Java code.
Common Lisp, used in the real-world albeit not wildely so, I guess.
Python or Ruby. See Paul Graham's thoughts on this in the question "I like Lisp but my company won't let me use it. What should I do?".
Scala is the absolute king of languages which have adopted significant academic features. Higher kinds, self types, polymorphic pattern matching, etc. All of these are bleeding-edge (or near to it) academic research topics that have been incorporated into Scala as fundamental features. Arguably, this has been to the detriment of the langauge's simplicity, but it does lead to some very interesting patterns.
C# is more mainstream than Scala, but it also has adopted fewer of these "out-there" functional features. LINQ is a limited implementation for Wadler's generalized list comprehensions, and everyone knows about lambdas. But for all that, C# (rightfully) remains a bit conservative in adopting research features from the academic world.
Erlang has recently gained renewed exposure not only through being used by Twitter, but also by the rise of XMPP driven messaging and implementations such as ejabberd. It sports many of the ideas coming from functional programming being a language designed with that in mind. Initially used to run Telephone switches and conceived by Ericson to run the first GSM networks. It is still around, it is fully functional (as a language) and used in many production environments.
Lua.
It's used as a scripting/extension language for a number of games (like World of Worcraft), and applications (Snort, NMAP, Wireshark, etc). In fact, according to an Adobe developer, Adobe's Lightroom is over 40% Lua.
The guys behind Lua have repeatedly listed Scheme and Lisp as major influences on Lua, and Lua has even been described as Scheme without the parentheses.
Have you checked out F#
Lot's of dynamic programming languages implement ideas from functional programming. The newer .Net languages (C# and VB) have what they call lambda's but these aren't side effect free.
It's not difficult combining concepts from functional programming and object oriented programming for example but it doesn't always make a lot of sense. Object oriented languages (try to) encapsulate state inside objects while functional languages encapsulate state inside functions. If you combine objects and functions in one language it gets harder to make sense of all this.
There have been a lot of languages that have combined these paradigms by just throwing them together (F#) and this can be usefull but I think we still need a couple of decades of playing with languages like this untill we can create a new paradigm that succesfully will combine the ideas from oo and functional programming.
C# 3.0 definitely does.
C# now has
Lambda Expressions
Higher Order Functions
Map / Reduce + Filter ( Folding?) to lists and all types which implement IEnumerable.
LINQ
Object + Collection Initializers.
The last two list items may not fall under proper functional programming, anyways the answer is C# has implemented many useful concepts from Lisp etc.
In addition to what was said, a lot of LISP goodness is based on guaranteed lack of side-effects and using built-in data structures. Both rarely hold in real world. ML is probably better functional base.
Lisp developed a set of interesting language features quite early on in the academic
world, but most of them never caught on in production environments.
Because the kind of people who manage software developers aren't the kinds of people who you can have an interesting chat comparing different language features with. Around 2000, I wanted to use LISP to implement XML-to-HTML transforms on our corporate website (this is around the time of Amazon implementing their backend in LISP). I didn't get to. This is mildly ironic seeing as the company I was working for made and sold a Common LISP environment.
Another "real-world" language that implements functional programming features is Javascript. Since absolutely everything has a value, then high-order functions are easily implemented. You also have other tenants of functional programming such as lambda functions, closures, and currying.
The features you refer to ("powerful" macros, the code-as-data thing and custom control structures) have not propagated within other functional languages. They died after Lisp taught us that they are a bad idea.
Modern functional languages (OCaml, Haskell, Erlang, Scala, F#, C# 3.0, JavaScript) do not have those features.
Cheers,
Jon Harrop.

Resources