[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 =
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的更多相关文章
- JS Function Arguments
		Function arguments在ECMAScript中的行为并不像其他大多数语言中的函数参数. 在ECMAScript中,function 并不关心有多少个参数传入函数中,也不关心传入参数的数据 ... 
- [Javascript] Required function arguments in Javascript
		In Javascript, all function arguments are optional by default. That means if you ever forget to pass ... 
- how to tell a function arguments length in js
		how to tell a function arguments length in js JavaScript函数不对参数值(参数)执行任何检查 https://www.w3schools.com/ ... 
- js function arguments types
		js function arguments types https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functi ... 
- JavaScript Function arguments.callee  caller length  return
		一.Function 函数是对象,函数名是指针. 函数名实际上是一个指向函数对象的指针. 使用不带圆括号的函数名是访问函数指针,并非调用函数. 函数的名字仅仅是一个包含指针的变量而已.即使在不同的环境 ... 
- JavaScript Function.arguments 属性详解
		语法 [functionObject.]arguments arguments属性是正在执行的函数的内置属性,返回该函数的arguments对象.arguments对象包含了调用该函数时所传入的实际参 ... 
- [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 ... 
- Parse the main function arguments
		int main(int argc, char **argv) { std::string reportDir; std::string transURL; std::string visualEle ... 
- pytest4-单文件使用fixture(Fixtures as Function arguments)
		Fixtures as Function arguments (fixture作为函数参数传入)Test functions can receive fixture objects by naming ... 
随机推荐
- jtagger Versatile multiprogrammer for FPGAs, MCUs, etc.
			jtagger Versatile multiprogrammer for FPGAs, MCUs, etc. Well, it's not really just a jtagger, but I' ... 
- c#调用刀片小票打印机
			public static bool Print(int orderId, string orderTime) { bool b = true; string cut = ((char)29).ToS ... 
- [廖雪峰] Git 分支管理(2):Bug 分支
			软件开发中,bug 就像家常便饭一样.有了 bug 就需要修复,在 Git 中,由于分支是如此的强大,所以,每个 bug 都可以通过一个新的临时分支来修复,修复后,合并分支,然后将临时分支删除. 当你 ... 
- [Office Web Apps]实现在线office文档预览
			摘要 在使用office web apps实现office文档在线预览的时候,需要注意的地方. web api web api作为owa在线预览服务回调的接口,这里面核心代码片段如下: using H ... 
- jeffy-vim-v3.2
			jeffy-vim-v3.2 增加了vim-gutentags 插件,支持tags自动生成. 
- AngularJS中实现显示或隐藏动画效果的3种方式
			本篇体验在AngularJS中实现在"显示/隐藏"这2种状态切换间添加动画效果. 通过CSS方式实现显示/隐藏动画效果 思路: →npm install angular-anima ... 
- DirectInfo.GetFiles返回数组的默认排序
			NTFS和CDFS下,是按照字母顺序,而FAT下,按照文件创建时间顺序 using System; using System.Collections; using System.IO; namespa ... 
- springboot static方法与构造方法加载@VALUE
			application.properties文件 mongodb.host=host111 mongodb.port=port222 import org.springframework.beans. ... 
- 咏南Mormot中间件接口
			咏南Mormot中间件接口 只使用了MORMOT的HTTPS.SYS作为通讯,数据引擎使用FIREDAC,数据序列/还原是自行封装. 客户端支持FDMemeTable和ClientDataSet数据集 ... 
- div与span区别及用法
			DIV与SPAN区别及div与san用法篇 接下来了解在div+css开发的时候在html网页制作,特别是标签运用中div和span的区别及用法.新手在使用web标准(div css)开发网页的时候, ... 
