hello.hs haskell

hello.ns

-- 创建模块 Main 首字母大写
module Main where

-- 导入可能用到的模块
import System.Environment

-- haskell 程序首先会执行 Main模块的 main action

-- main :: IO () 是type 声明, 这里可省略
-- type :: IO 是monad的实例,
main :: IO ()
-- 等号左边是 定义一个 name
-- 等号右边是 其他定义的组合
-- 这里有do-block
main = do
    args <- getArgs
    putStrLn ( "Hello, " ++ args !! 0 )

--1 name <- action
-- 把 getArgs 的结果bind到 name
--2 action
-- 仅执行action

-- args !! 0 args列表的第0个元素
-- ++ 是 list concatenation


-- 函数式编程的一个重要的概念是 referential transparency 透明引用, 没有side-effect 边界效应

编译

ghc hello.hs

./hello.hs Wold

Hello, World

... great haskell

原文地址:https://www.cnblogs.com/kwingmei/p/3730658.html