sábado, 20 de agosto de 2016

Frege como Haskell pero en la plataforma Java


Siempre me pregunte como no habia un leguaje igual a Haskell pero que corra en la plataforma java y aca esta!! Frege, que si vien no es una copia exacta de Haskell tiene mucha similitud.

Este lenguaje soporta muchas características de haskell, como:

  • Typeclasses con polimorfismo
  • Pattern matching
  • Listas por compresión
  • módulos
  • Abstracción matemática que nos permite tenes estructuras como functors, monoids, semigroups, y monads.


Veamos un poco de código:

-- file hello.fr
module Hello where  -- moduleName maybe hierarchical as pkgdir.JavaClassname

main args = println $ "Hello world! your arguments are: " ++ show args

En este ejemplo se puede ver un simple hello world. Como ven es mu similar a haskell para tiene una clara influencia de la plataforma java.

Veamos otro ejemplo:

{--
    Este programa muestra la
     hora actual en la salida estándar
     cada dos segundos.
    -}
   
module examples.CommandLineClock where

data Date = native java.util.Date where
    native new :: () -> IO (MutableIO Date)             -- new Date()
    native toString :: Mutable s Date -> ST s String    -- d.toString()

--- 'IO' action to give us the current time as 'String'
current :: IO String
current = do
    d <- Date.new ()  -- reads system timer, hence IO
    d.toString

main args =
    forever do
        current >>= print   -- print formatted date
        print "\r"          -- followed by carriage return
        stdout.flush        -- make sure it's shown
        Thread.sleep 999L   -- wait 0.999 seconds


Este lenguaje fue diseñado por Ingo Wechsung quien nombra este lenguaje Frege por el matemático alemán Gottlob Frege.

Además podemos probarlo de forma online desde esta pagina: http://try.frege-lang.org/

Dejo links:
https://github.com/Frege/frege
https://en.wikipedia.org/wiki/Frege_(programming_language)

No hay comentarios.:

Publicar un comentario