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?
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.
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.
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.
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.
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.
Frege's type inference is global so we don't have to annotate types as often as we do in Scala (local inference).
In Frege, modules are just namespaces for types and functions whereas Scala has better module system. http://2013.flatmap.no/spiewak.html
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.
In Frege, there is no def
vs val
and everything is function. Hence functions are more first-class than Scala.
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.
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
.
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!)
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With