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 =

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 -> \b -> a + b

We can also define curry function:

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

Full code:

module Main where

import Prelude
import Control.Monad.Eff.Console (log)
import TryPureScript myTypes :: Int
myTypes = -- add (a -> (b -> (a + b)))
add :: Int -> Int -> Int
add a b = a + b
addMe = \a -> \b -> a + b -- inc (a -> (add 1 a))
inc :: Int -> Int
inc = add main = render =<< withConsole do
log $ show $ inc 5 // 6

[PureScript] Introduce to PureScript Specify Function Arguments的更多相关文章

  1. JS Function Arguments

    Function arguments在ECMAScript中的行为并不像其他大多数语言中的函数参数. 在ECMAScript中,function 并不关心有多少个参数传入函数中,也不关心传入参数的数据 ...

  2. [Javascript] Required function arguments in Javascript

    In Javascript, all function arguments are optional by default. That means if you ever forget to pass ...

  3. how to tell a function arguments length in js

    how to tell a function arguments length in js JavaScript函数不对参数值(参数)执行任何检查 https://www.w3schools.com/ ...

  4. js function arguments types

    js function arguments types https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functi ...

  5. JavaScript Function arguments.callee caller length return

    一.Function 函数是对象,函数名是指针. 函数名实际上是一个指向函数对象的指针. 使用不带圆括号的函数名是访问函数指针,并非调用函数. 函数的名字仅仅是一个包含指针的变量而已.即使在不同的环境 ...

  6. JavaScript Function.arguments 属性详解

    语法 [functionObject.]arguments arguments属性是正在执行的函数的内置属性,返回该函数的arguments对象.arguments对象包含了调用该函数时所传入的实际参 ...

  7. [Ramda] Eliminate Function Arguments (Point-Free Style) with Ramda's Converge

    When doing comparisons inside of functions, you end of relying heavily on the argument passed into t ...

  8. Parse the main function arguments

    int main(int argc, char **argv) { std::string reportDir; std::string transURL; std::string visualEle ...

  9. pytest4-单文件使用fixture(Fixtures as Function arguments)

    Fixtures as Function arguments (fixture作为函数参数传入)Test functions can receive fixture objects by naming ...

随机推荐

  1. Optimizing Oracle RAC

    Oracle Real Application Clusters (RAC) databases form an increasing proportion of Oracle database sy ...

  2. linux内核数据包转发流程(二):中断

    [版权声明:转载请保留出处:blog.csdn.net/gentleliu.邮箱:shallnew*163.com] 内核在处理2层数据包之前,必须先处理中断系统.设立中断系统,才有可能每秒处理成千的 ...

  3. HBase的JavaAPI使用

    Java Client API Overview HBase是用Java写的,支持用编程语言来动态操作管理数据库,能用命令行做的都能够用API来做. 主要的使用步骤例如以下: 1.创建一个 Confi ...

  4. 一分钟掌握Android spinner下拉框

    Android 自带的spinner下拉框控件是一个不错的系统控件.主要有两种实现方式: 1.静态的spinner 在res\values中加入一个city资源数组文件 2 <resources ...

  5. Linux线程优先级

    转自:https://www.cnblogs.com/imapla/p/4234258.html Linux内核的三种调度策略: 1.SCHED_OTHER 分时调度策略 2.SCHED_FIFO   ...

  6. Android组件化方案

    Android组件化项目地址:Android组件化项目AndroidModulePattern Android组件化之终极方案地址:http://blog.csdn.net/guiying712/ar ...

  7. HTML5 Geolocation API地理定位整理(二)

    Geolocation 实例demo 1.使用watchPosition()监听客户端位置 var watchOne=null; if (navigator.geolocation) { //watc ...

  8. 深入理解多线程(二)—— Java的对象模型

    上一篇文章中简单介绍过synchronized关键字的方式,其中,同步代码块使用monitorenter和monitorexit两个指令实现,同步方法使用ACC_SYNCHRONIZED标记符实现.后 ...

  9. DAU预测

    转自: http://www.kaixin001.com/repaste/80488684_6910412734.html 我们知道在所有的游戏运营数据中,最终要的两个数据莫过于DAU.ARPU了.| ...

  10. [转]PHP traits

    From : http://www.php.net/manual/zh/language.oop5.traits.php 自 PHP 5.4.0 起,PHP 实现了代码复用的一个方法,称为 trait ...