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. PL/SQL Developer中调试oracle的存储过程

    作者:iamlaosong 唉,真土,曾经用Toad.一直用dbms_output.put_line调试存储过程,仅仅认为不方便,用上PL/SQL Developer后,习惯性的还是用这种方法.人都是 ...

  2. Cocos2d-x3.1TestCpp之NewRenderTest Demo分析

    1.代码构成 VisibleRect.h VisibleRect.cpp AppDelegate.h AppDelegate.cpp HelloWorldScene.h HelloWorldScene ...

  3. lufylegend:图形变形2

    下面来详细讲解一下drawtriangles函数的使用方法.并且使用drawtriangles函数实现下面这种处理效果 因为这个方法是从AS3移植而来,所以它的使用方法和AS3基本一致,这里是AS3的 ...

  4. 在im4java中使用GraphicsMagick

    1.定义操作和命令GMOperation op = new GMOperation();GraphicsMagickCmd cmd = new GraphicsMagickCmd("conv ...

  5. Chrome 如何知道网站启用了SPDY 协议?

    地址栏输入chrome://net-internals/#spdy 在host后查看协议,google和dropbox用https协议的开启了 3. 也可以通过安装插件来查看(SPDY Indicat ...

  6. linux 下查看硬盘分区类型

    可以用  df 这个命令 具体 要 man df  仔细看看 实例 [root@localhost mnt]# df -Th文件系统    类型      容量  已用  可用 已用% 挂载点/dev ...

  7. Raspbian 中国软件源

    转自:http://shumeipai.nxez.com/2013/08/31/raspbian-chinese-software-source.html 花了些时间整理了目前最新的树莓派中国大陆地区 ...

  8. 维京传奇第四季/全集Vikings迅雷下载

    英文全名Vikings,第4季(2015). 本季看点:<维京传奇>当第四季开始时,Ragnar已经病入膏肓,随时可能丧命.毫无疑问,权力斗争异常激烈,谁都想在Ragnar死后获得最大利益 ...

  9. pycurl post

    pc = pycurl.Curl() pc.setopt(pycurl.POST, 1) pc.setopt(pycurl.URL, 'http://192.168.0.25:/Image') #pc ...

  10. Asp.Net Core获取请求信息/获取请求地址

     一.Asp.Net Core 2.0版本中目前HttpRequest是个抽象类 在控制器或视图上下文中获取到的 Request对象,是 DefaultHttpRequest的实例. 定义 如图 : ...