Frege is an actively used programming language created in 2011. Frege is a non-strict, purely functional programming language for the Java virtual machine in the spirit of Haskell. It is considered a Haskell dialect or simply "a" Haskell for the Java virtual machine. Frege has a strong static type system with type inference. Read more on Wikipedia...

8Years Old 27Users 0Jobs

Example code from Linguist:

{-- 
    This program displays the
    current time on stdandard output
    every other second.
    -}
    
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 ()
    d.toString

{- 
    "java.lang.Thread.sleep" takes a "long" and
    returns nothing, but may throw an InterruptedException.
    This is without doubt an IO action.
    
    public static void sleep(long millis)
                  throws InterruptedException
    
    Encoded in Frege:
    - argument type  long   Long
    - result         void   ()
    - does IO               IO ()
    - throws ...            throws ....
     
-}
-- .... defined in frege.java.Lang
-- native sleep java.lang.Thread.sleep :: Long -> IO () throws InterruptedException

      
main args =  
    forever do
        current >>= print
        print "\r"
        stdout.flush
        Thread.sleep 999
                

Example code from Wikipedia:

{-- 
    This program displays the
    current time on standard output
    every other second.
    -}
    
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

Last updated July 22nd, 2019