4

In my learning curve of Haskell, I am trying to find correspondent pairs of features in either language:

Haskell concept        <=>  Approximate equivalent C++ Concept

Data (Record syntax)   <=>  Class/Struct

Typeclass              <=>  Abstract Class (Interface in Java)

Type Constructor       <=>  Template

Functor                <=>  Iterable class (https://stackoverflow.com/questions/8164567/how-to-make-my-custom-type-to-work-with-range-based-for-loops) 

fmap                   <=>  std::transform 

lambda                 <=>  lambda (>= C++11)  (without capture mecanism)

type                   <=>  alias ( >= c++11), typedefs

type inference         <=>  type inference ( >= c++11 auto)

module                 <=>  library

Maybe                  <=>  std::optional (>= C++17)

Either                 <=>  std::variant (>= C++17)

Higher Order Function  <=>  functions taking one or several function pointers or std::function as parameter 

Tuples                 <=>  std::tuple (>= C++11)

Haskell Concepts with no equivalence

Pattern matching 
IO
List comprehension (C++ std::initializer_list ?) 

Do you see important concepts that I should add in this list or obvious errors?

leftaroundabout
  • 117,950
  • 5
  • 174
  • 319
sandwood
  • 2,038
  • 20
  • 38
  • 5
    A `Functor` is not an iterable, for instance a function is a `Functor` as well. – Willem Van Onsem Apr 06 '18 at 08:41
  • 1
    For something like iterable, look at [`Data.Foldable`](https://hackage.haskell.org/package/base-4.11.0.0/docs/Data-Foldable.html). I'm not a C++ buff, but it seems that `fmap` can do more than `std::transform` since functors are not just containers. – sshine Apr 06 '18 at 08:45
  • [C++ has pattern matching through Mach7](https://github.com/solodon4/Mach7). It has Bjarne Stroustrup in the credits, but I bet it isn't commonly used at all. As [this SO post](https://stackoverflow.com/questions/20765979/c-equivalent-of-algebraic-datatype) suggests, another way of dealing with algebraic data types in C++ is [`boost::variant`](https://www.boost.org/doc/libs/1_64_0/doc/html/variant.html). – sshine Apr 06 '18 at 08:54
  • 1
    It seems that this approximation can vary quite a lot depending on what you are trying to achieve with it and is rather opinion based. I think most of these are completely wrong. For example C++ has no functions and no higher order functions at all from haskell perspective while haskell does not expose functions from c++ perspective. – user7860670 Apr 06 '18 at 08:54
  • When you write "Class" in the Haskell column, I assume you mean type class? Neither abstract classes nor interfaces are perfect translations to OOP terminology. Another weak comparison is [C++ Concepts vs. Haskell type classes](https://stackoverflow.com/questions/32124627/how-are-c-concepts-different-to-haskell-typeclasses). See [HaskellWiki's OOP vs. type classes](https://wiki.haskell.org/OOP_vs_type_classes) for a more thorough comparison. In fact, if you google most "Haskell vs. ", you get a bunch of results. – sshine Apr 06 '18 at 09:00
  • 1
    Please don't use the term "C++ concepts" in this way: "concept" now is a precise technical meaning in C++ (like "template"), even if they are not yet in the standard (AFAIK). You are using it in its English sense. Perhaps "constructs" or "features" are more appropriate, here. – chi Apr 06 '18 at 09:57
  • 1
    And `'' <=> 'const'` ;-) – luqui Apr 06 '18 at 10:00
  • @chi: If you are speaking to me, I am referring to "C++ Concepts" as a proper noun just like the author/implementor that I'm linking to ("as defined by the Concepts TS") . I am using "C++ Concepts" in the "English sense" in the sense that I am writing English, yes, but other than that, I rely fully on how the author uses it. I've never heard of it before today. – sshine Apr 06 '18 at 11:05
  • Basically, all of these are wrong or at least only 'correct' in such an abstract sense that they're basically meaningless. Language features and metaphors don't translate well across paradigms. – Cubic Apr 06 '18 at 11:32
  • My immediate reaction is "Why are you trying to do this? What problem are you trying to solve?" If you're trying to make Haskell seem just like C++... well, it isn't, and it's probably going to confuse more than illuminate. But maybe you had some other purpose in mind? – MathematicalOrchid Apr 06 '18 at 12:06
  • C++ classes and Haskell typeclasses are not the same thing. A C++ class is both a set of types (its descendants) and a type in itself, but a Haskell typeclass is only a set of types. – Paul Johnson Apr 06 '18 at 12:10

0 Answers0