📜  eta 完整形式 (1)

📅  最后修改于: 2023-12-03 15:30:39.100000             🧑  作者: Mango

Eta - A Complete Functional Programming Language for the JVM

Eta is a strongly-typed, pure functional programming language built upon the Haskell programming language. It is designed to seamlessly integrate with the existing Java ecosystem, including support for full interoperation with existing Java code and libraries.

Key Features
  • Pure functional programming with pervasive immutability
  • Algebraic data types and pattern matching
  • Lazy evaluation and strict evaluation annotation
  • Type classes and higher-kinded types
  • Polymorphism and type inference
  • Built in concurrency support with lightweight threads
  • Full interoperation with Java code and libraries
Getting started

To get started with Eta, you can download the latest version from the official website here. Once you have downloaded and installed the Eta compiler, you can start writing Eta code.

A simple Eta program

Here is a simple program written in Eta to demonstrate the syntax and features of the language:

-- Define a function to calculate the factorial of a number
factorial :: Int -> Int
factorial 0 = 1
factorial n = n * factorial (n - 1)

-- Define a main function to print the factorial of 10
main :: IO ()
main = putStrLn $ "Factorial of 10 is " ++ show (factorial 10)

In this example, we define a function factorial to calculate the factorial of a number using recursion and pattern matching. We also define a main function to print the factorial of 10 using the putStrLn function from the IO library and the show function to convert the integer result to a string.

Interoperating with Java

One of Eta's key features is its ability to interoperate with existing Java code and libraries. Here is an example of an Eta program that calls a Java library method to print the current time:

import java.time.LocalDateTime

main :: IO ()
main = do
  let now = LocalDateTime/now
  putStrLn $ "Current time is: " ++ show now

In this example, we import the java.time.LocalDateTime class from the Java runtime library and call its now method to get the current time. We then use the putStrLn function to print the time to the console.

Conclusion

Eta is a complete functional programming language that provides a powerful set of features for building robust and scalable applications. Its seamless integration with the existing Java ecosystem makes it easy to use and learn for existing Java developers.