1

I'm looking for an interpreted language that's easy for quick scripting like or but has more of a Haskell feel to it (i.e. a functional language).

Specifically, I want it to have pattern matching features like in haskell. Does such a thing exist?

EDIT: I mainly ask because I like learning new languages and I noticed there was an empty spot in the languages I've been learning.
On the one hand I had interpreted and dynamically typed languages like Python and Ruby that had functional elements, but didn't take the concept too far.
On the other hand I had Haskell which has many of the functional features I enjoy but is very strict (it takes me a fair amount of time to get even simple programs to work).
I was just wondering if there is something that splits these differences.

MasterMastic
  • 20,711
  • 12
  • 68
  • 90
yorble
  • 81
  • 4
  • 6
    Haskell is easy for quick scripting.... – Sibi Aug 26 '14 at 08:52
  • 2
    Racket offers pattern matching, is functional, and "impure" as scripting languages are. Whether it is "easy" or not is very subjective IMHO, like any other language. – chi Aug 26 '14 at 09:46
  • Try HUGS, it's a Haskell implementation. – augustss Aug 26 '14 at 10:17
  • Why do you want an interpreter? – Don Stewart Aug 26 '14 at 10:34
  • I've found Ruby enough of *functional feel*. There is a nice gem called [contracts](https://github.com/egonSchiele/contracts.ruby) which draws programming nearer to haskell and can help catch many errors at design time. I'm curious why are you asking particular for pattern matching, what do you expect from this. – David Unric Aug 26 '14 at 15:11
  • F# has a REPL mode with F Sharp Interactive: http://msdn.microsoft.com/en-ca/library/dd233175.aspx and supports pattern matching. – mattnewport Aug 26 '14 at 18:13
  • @chi racket looks very interesting, great suggestion. – yorble Aug 27 '14 at 08:32
  • @DonStewart good question... to be honest I'm not really sure. I'll edit to clarify my thoughts. – yorble Aug 27 '14 at 08:34
  • @DavidUnric I just enjoy pattern matching as a feature. – yorble Aug 27 '14 at 08:44

1 Answers1

13

Haskell

You can use runhaskell to execute a haskell file. The file is run immediately like a python script.

runhaskell test.hs

Prints Hello Wolrd!

If test.hs contains

main = putStrLn "Hello World!"

Scala

Another language that is less pure would be Scala. It targets the JVM and can therefore use all Java Libraries. You can use it as a script with:

scala test.scala

Where test.scala is just:

println("Hello, World!")

For pattern matching there is match case:

def headSafe[A](arg: List[A]):Option[A] = arg match {
  case x::xs => Some(x)
  case _     => None
}

Option corresponds to Haskells Maybe monand. If you are interested in scala you can have a look at http://scala-lang.org

bmaderbacher
  • 1,261
  • 1
  • 10
  • 19