Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the main differences between Scala and Frege (in programming paradigms)?

Scala and Frege are both typed functional languages that target JVM.

Frege is closer to Haskell, Scala has a more independent history.

But if we don't look at syntactic differences, what are the differences in the allowed programming techniques, styles, concepts between the two?

like image 486
imz -- Ivan Zakharyaschev Avatar asked Jul 28 '13 05:07

imz -- Ivan Zakharyaschev


People also ask

What is Scala programming paradigm?

Scala is a modern multi-paradigm programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It seamlessly integrates features of object-oriented and functional languages.

How is Scala different from other languages?

Advantages of ScalaThe code is more concise, readable, and error-free. It is easy to write, compile, debug, and run the program in Scala, when compared to many other programming languages. Functional programming lets you approach the same problem in a different angle.

How is Scala different?

Scala, got it as a name after it's a feature called scalability that makes Scala unique from other programming languages. There is no concept of primitive data in Scala as everything is an object. The language is designed to exhibit common programming language in a more graceful, snappy, and type-safe manner.

What are the differences between functional and procedural programming languages?

Procedural languages tend to keep track of state (using variables) and tend to execute as a sequence of steps. Purely functional languages don't keep track of state, use immutable values, and tend to execute as a series of dependencies.


1 Answers

IMHO both are really good languages but with respect to paradigms, Scala does OO better than Frege but Frege does functional better than Scala. With respect to differences, it comes down to mostly Haskell vs Scala since Frege is (or almost, see differences between Haskell and Frege here) Haskell for the JVM.

  1. Frege's type inference is global so we don't have to annotate types as often as we do in Scala (local inference).

  2. In Frege, modules are just namespaces for types and functions whereas Scala has better module system. http://2013.flatmap.no/spiewak.html

  3. In Frege, functions are curried by default so there is no need for additional constructs for partial function application. Same goes for partial type constructor application.

  4. In Frege, there is no def vs val and everything is function. Hence functions are more first-class than Scala.

  5. Frege has no sub-typing but the type system figures out the sub typing on native calls. For example, you can pass an ArrayList to a function which requires a Java List.

    Since there is no subtyping, in Frege we cannot extend a Java class or implement an interface as of now (might be supported in future) so we need to have a Java class which would extend/implement but the method implementations would be passed from Frege as functions.

  6. From Scala, it is easy to call Java but in Frege, a Java class/method must be declared (Just the type and purity annotations) before use. For example, to use Java's LinkedList,

    data LinkedList a = native java.util.LinkedList where     native add :: Mutable s (LinkedList a) -> a -> ST s Bool     native get :: Mutable s (LinkedList a) -> Int -> ST s (Maybe a) throws        IndexOutOfBoundsException     native new :: () -> STMutable s (LinkedList a) 

    Here since the functions mutate the object, they must be in ST monad. Also note that here Frege also handles null returned from the get method since it is annotated with Maybe type. The only way null can get through to your Frege program is through native interface since Frege doesn't have a notion of null.

    Another example: pure native floor Math.floor :: Double -> Double

    which states that the function is pure and hence the signature directly reflects the original Java signature without IO or ST.

  7. Frege has no variables as in Scala's var and the side effects are more explicit through types. (Just no null, no var and explicit side effects make Frege more interesting, atleast for me. In a sense, Frege, just as Haskell, is a "fine imperative programming language", for the JVM!)

  8. Being a Haskell dialect, Frege is more natural towards Functors, Applicatives, Monads and other functional "patterns" and has those in it's standard library whereas in Scala, you might need Scalaz.

  9. Frege is lazy by default but strictness can be enabled where necessary through ! whereas Scala is strict by default but has lazy keyword for lazy evaluation.

Nevertheless, being JVM languages, one language can benefit from other. I once ported an Akka example to Frege. In the end, it comes down to strictness, purity, functional, OO and type inference and how much they matter to you.

like image 73
Marimuthu Madasamy Avatar answered Oct 02 '22 12:10

Marimuthu Madasamy