Search code examples
haskellfunctional-programmingpattern-matchingscripting-languageinterpreted-language

Please recommend an interpreted language with pattern matching


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.


Solution

  • 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