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. An Isolated DAC Using PWM Output

    An Isolated DAC Using PWM Output Arduino‘s (ATmega328P) PWM outputs via analogWrite can be convenien ...

  2. TIDB VS COCKROACHEB

    分布式事务 要支持分布式事务,首先要解决的就是分布式系统时间的问题,也就是我们用什么来标识不同事务的顺序.通常有几种做法: TrueTime,TrueTime 是 Google Spanner 使用的 ...

  3. go实现 raft Paxos 算法

    https://github.com/happyer/distributed-computing https://www.zhihu.com/people/ding-kai-54/posts

  4. DOM对象之document对象

    DOM对象:当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model). HTML DOM 模型被构造为对象的树. 打开网页后,首先看到的是浏览器窗口,即顶层的win ...

  5. 在Visual Studio中使用序列图描述对象之间的互动

    当需要描述多个对象之间的互动,可以考虑使用序列图. 在建模项目下添加一个名称为"Basic Flow"的序列图. 比如描述客户是如何在MVC下获取到视图信息的. 备注: ● 通常是 ...

  6. Unity3D实践系列09, 物理引擎与碰撞检测

    在Unity3D中,一个物体通常包含一个Collider和一个Rigidbody.Collider是碰撞体,一个物体是Collider,才可以进行碰撞检测.Collider组件中的"Is T ...

  7. SpringBoot中Mybatis打印sql

    原文:https://www.cnblogs.com/expiator/p/8664977.html 如果使用的是application.properties文件,加入如下配置: logging.le ...

  8. [转]浅论ViewController的加载 -- 解决 viewDidLoad 被提前加载的问题(pushViewController 前执行)

    一个ViewController,一般通过init或initWithNibName来加载.二者没有什么不同,init最终还是要调用initWithNibName方法(除非这个ViewControlle ...

  9. 教你调用数据库读取短信 记事本 通讯录文件,让ios5的短信恢复到ios4

    由于高版本的ios固件向下恢复到低版固件时无法通过itunes恢复备份,所以一些数据,比如SMS需要通过提取文件的方式单独进行备份恢复特别是ios5的短信,之前很是头痛,直接将文件恢复到指定目录修改权 ...

  10. 深入理解多线程(三)—— Java的对象头

    上一篇文章中我们从HotSpot的源码入手,介绍了Java的对象模型.这一篇文章在上一篇文章的基础上再来介绍一下Java的对象头.主要介绍一下对象头的作用,结构以及他和锁的关系. Java对象模型回顾 ...