5

I am a Scala beginner and coming from Object Oriented Paradigm. While understanding Functional programming part of Scala, I was directed to Haskell - the pure Functional programming language.

Exploring SO question-answers, I found that Java - Haskell has interoperability.

I am curious to know that similarly does Scala-Haskell interoperability exist or not?

Can a function library written in Haskell be used in Scala application?

As per answer given by Don Stewart: It is possible.

Integration of Haskell Function Library in Scala application will be straight and easy or will require complicated tweaks?

With integrated Haskell Function Library, the Scala application will run on JVM or will require different arrangement?

Optimight
  • 2,809
  • 3
  • 25
  • 42
  • 1
    If there's Java–Haskell interop, then using Scala in Haskell should be no different to using Java. Scala compiles to regular Java classes, albeit with some extra runtime support from Scala "builtins". – Asherah Jun 24 '12 at 07:11

2 Answers2

4

It is possible, but I am not aware of any examples.

Don Stewart
  • 134,643
  • 35
  • 355
  • 461
  • 4
    It will be complicated if you try and link the JVM and GHC rts together. It will be easy if you communicate through a protocol, e.g. JSON. – Don Stewart Jun 22 '12 at 19:52
  • I mean...in some ways, I almost want to ask if it'd be easier to compile C-- and the like to Java bytecode, though linking the RTS back in would make things...interesting. – Louis Wasserman Jun 23 '12 at 14:49
4

I found that Java - Haskell has interoperability. I am curious to know that similarly does Scala-Haskell interoperability exist or not?

Well given that interoperability is transitive, and given that (hj_interop : Haskell <-> Java) and (js_interop : Java <-> Scala), we therefore conclude that Haskell <-> Scala.

If you want Haskell -> Scala, then just take Haskell -> Java from hj_interop, and Java -> Scala from js_interop. If you want Scala -> Haskell, then just take Scala -> Java from js_interop, and Java -> Haskell from hj_interop.

This isn't a very hand-holdy explanation of how to accomplish Haskell - Scala interoperability, but given existing interoperatilities, you just compose them in the obvious way. Scala does not provide any direct, convenient interoperability with Haskell that I am aware of, other than providing scalaz to add an extra Haskell-y feel to Scala. Haskell does not provide any direct, convenient interoperability with Scala that I am aware of.

Dan Burton
  • 51,332
  • 25
  • 109
  • 190
  • What can be the performance issues, if Scala -> Haskell is achieved by , by using Scala -> Java from js_interop, and Java -> Haskell from hs_interop. Here the main purpose is to get benefit of haskell's heavy Functionall Programming Strengths. – Optimight Jun 23 '12 at 00:03
  • scala java interop has effectively zero cost. All that said, if you want to write Haskell-like code in scala, just install scalaz and write a lot more type signatures. :) – Edward KMETT Jun 26 '12 at 23:57
  • You might be interested to the Frege project ( http://code.google.com/p/frege/ ), which puts a very Haskell-like language on the JVM. I admit the Java interoperability has still room for improvement, but is built in, and the compiler emits very funny Java *source* files. – Landei Jul 12 '12 at 12:16