zoukankan      html  css  js  c++  java
  • [PureScript] Introduce to PureScript Specify Function Arguments

    JavaScript does its error-checking at runtime, but PureScript has a compiler, which makes sure that your program has no errors before it converts it all into JavaScript.

    PureScript's compiler uses a type system to catch errors so that you aren’t accidentally mismatching your types. We will learn the very basics of type declarations, how they work in a statically typed language like PureScript, and see simple examples of them in action.

    Join in by going to PureScripts online editor

    Define a variable type:

    myTypes :: Int
    myTypes = 1

    Define a function:

    add :: Int -> Int -> Int // Take a Int, another Int, return value is also Int
    add a b = a + b

    We can also define the function like that:

    add = a ->  -> a + b

    We can also define curry function:

    -- inc (a -> (add 1 a))
    inc :: Int -> Int
    inc = add 1
    
    main = render =<< withConsole do
      log $ show $ inc 5

    Full code: 

    module Main where
    
    import Prelude
    import Control.Monad.Eff.Console (log)
    import TryPureScript
    
    myTypes :: Int
    myTypes = 1
    
    -- add (a -> (b -> (a + b)))
    add :: Int -> Int -> Int
    add a b = a + b
    addMe = a ->  -> a + b
    
    -- inc (a -> (add 1 a))
    inc :: Int -> Int
    inc = add 1
    
    main = render =<< withConsole do
      log $ show $ inc 5 // 6
  • 相关阅读:
    HDU6808 Go Running(未解决问题
    K
    E
    D
    B
    I
    HDU 2255 奔小康赚大钱 (KM算法模板)
    hdu 1150 Machine Schedule(二分图模板题)
    ACM-ICPC 2018 焦作赛区网络预赛G Give Candies(欧拉降幂)
    ACM-ICPC 2018 焦作赛区网络预赛 L:Poor God Water(杜教BM)
  • 原文地址:https://www.cnblogs.com/Answer1215/p/10623891.html
Copyright © 2011-2022 走看看