The Idris Tutorial Version 0.11syntax to Haskell. Natural numbers and lists, for example, can be declared as follows: data Nat = Z | S Nat -- Natural numbers -- (zero and successor) data List a = Nil | (::) a (List a) -- Polymorphic the standard library: -- Unary addition plus : Nat -> Nat -> Nat plus Z y = y plus (S k) y = S (plus k y) -- Unary multiplication mult : Nat -> Nat -> Nat mult Z y = Z mult (S k) y = plus y (mult k y) y) The standard arithmetic operators + and * are also overloaded for use by Nat, and are implemented using the above functions. Unlike Haskell, there is no restriction on whether types and function names0 码力 | 71 页 | 314.20 KB | 1 年前3
The Idris Tutorial Version 0.9.20.1syntax to Haskell. Natural numbers and lists, for example, can be declared as follows: data Nat = Z | S Nat -- Natural numbers -- (zero and successor) data List a = Nil | (::) a (List a) -- Polymorphic the standard library: -- Unary addition plus : Nat -> Nat -> Nat plus Z y = y plus (S k) y = S (plus k y) -- Unary multiplication mult : Nat -> Nat -> Nat mult Z y = Z mult (S k) y = plus y (mult k y) y) The standard arithmetic operators + and * are also overloaded for use by Nat, and are implemented using the above functions. Unlike Haskell, there is no restriction on whether types and function names0 码力 | 71 页 | 316.18 KB | 1 年前3
The Idris Tutorial Version 0.9.18syntax to Haskell. Natural numbers and lists, for example, can be declared as follows: data Nat = Z | S Nat -- Natural numbers -- (zero and successor) data List a = Nil | (::) a (List a) -- Polymorphic the standard library: -- Unary addition plus : Nat -> Nat -> Nat plus Z y = y plus (S k) y = S (plus k y) -- Unary multiplication mult : Nat -> Nat -> Nat mult Z y = Z mult (S k) y = plus y (mult k y) y) The standard arithmetic operators + and * are also overloaded for use by Nat, and are implemented using the above functions. Unlike Haskell, there is no restriction on whether types and function names0 码力 | 69 页 | 316.20 KB | 1 年前3
The Idris Tutorial Version 0.99e l l . Nat u r al n u m b e r s an d l i s t s , f or e x am p l e , c an b e d e c l ar e d as f ol l ow s : 5 C H A P T E R 1. T H E I D R I S T U T O R I A L v0. 99 data Nat = Z | S Nat -- Natural ar d l i b r ar y : -- Unary addition plus : Nat -> Nat -> Nat plus Z y = y plus (S k) y = S (plus k y) -- Unary multiplication mult : Nat -> Nat -> Nat mult Z y = Z mult (S k) y = plus y (mult k y) t an d ar d ar i t h m e t i c op e r at or s + an d * ar e al s o ov e r l oad e d f or u s e b y Nat, an d ar e i m p l e m e n t e d u s i n g t h e ab ov e f u n c t i on s . Un l i k e Has k e l l0 码力 | 182 页 | 1.04 MB | 1 年前3
Idris 语言文档 Version 1.3.1: String 1. 3. 2 数 数 数据 据 据类 类 类型 型 型 数据类型的声明方式和语法与 奈奡女 奫 奥 奬 奬 非常相似。例如,自然数和列表的声明如下: data Nat = Z | S Nat -- 自然数(零与后继) data List a = Nil | (::) a (List a) -- 多态列表 以上声明来自于标准库。一进制自然数要么为零(Z), 要么就是另一个自然数的后继(S 数定义如下,同样来自标准库: -- 一进制加法 plus : Nat -> Nat -> Nat plus Z y = y plus (S k) y = S (plus k y) -- 一进制乘法 mult : Nat -> Nat -> Nat mult Z y = Z mult (S k) y = plus y (mult k y) 标准算术运算符 + 和 * 同样根据 Nat 的需要进行了重载, 它们使用上面的函数来定义。和 ::) 以及类型构造器(Nat 和 List)均属同一命名空间。不过按照约定, 数据类型和 构造器的名字通常以大写字母开头。我们可以在 奉 奤 奲 奩 女 提示符中测试这些函数: Idris> plus (S (S Z)) (S (S Z)) 4 : Nat Idris> mult (S (S (S Z))) (plus (S (S Z)) (S (S Z))) 12 : Nat 注 注 注解 解0 码力 | 224 页 | 2.06 MB | 1 年前3
The Idris Tutorial Version 1.3.1m i l ar s y n t ax t o Has k e l l . Nat u r al n u m b e r s an d l i s t s , f or e x am p l e , c an b e d e c l ar e d as f ol l ow s : data Nat = Z | S Nat -- Natural numbers -- (zero and successor) ar d l i b r ar y : -- Unary addition plus : Nat -> Nat -> Nat plus Z y = y plus (S k) y = S (plus k y) -- Unary multiplication mult : Nat -> Nat -> Nat mult Z y = Z mult (S k) y = plus y (mult k y) t an d ar d ar i t h m e t i c op e r at or s + an d * ar e al s o ov e r l oad e d f or u s e b y Nat, an d ar e i m p l e m e n t e d u s i n g t h e ab ov e f u n c t i on s . Un l i k e Has k e l l0 码力 | 230 页 | 1.24 MB | 1 年前3
The Idris Tutorial Version 1.3.0m i l ar s y n t ax t o Has k e l l . Nat u r al n u m b e r s an d l i s t s , f or e x am p l e , c an b e d e c l ar e d as f ol l ow s : data Nat = Z | S Nat -- Natural numbers -- (zero and successor) ar d l i b r ar y : -- Unary addition plus : Nat -> Nat -> Nat plus Z y = y plus (S k) y = S (plus k y) -- Unary multiplication mult : Nat -> Nat -> Nat mult Z y = Z mult (S k) y = plus y (mult k y) t an d ar d ar i t h m e t i c op e r at or s + an d * ar e al s o ov e r l oad e d f or u s e b y Nat, an d ar e i m p l e m e n t e d u s i n g t h e ab ov e f u n c t i on s . Un l i k e Has k e l l0 码力 | 229 页 | 1.24 MB | 1 年前3
The Idris Tutorial Version 2.3.0m i l ar s y n t ax t o Has k e l l . Nat u r al n u m b e r s an d l i s t s , f or e x am p l e , c an b e d e c l ar e d as f ol l ow s : data Nat = Z | S Nat -- Natural numbers -- (zero and successor) ar d l i b r ar y : -- Unary addition plus : Nat -> Nat -> Nat plus Z y = y plus (S k) y = S (plus k y) -- Unary multiplication mult : Nat -> Nat -> Nat mult Z y = Z mult (S k) y = plus y (mult k y) t an d ar d ar i t h m e t i c op e r at or s + an d * ar e al s o ov e r l oad e d f or u s e b y Nat, an d ar e i m p l e m e n t e d u s i n g t h e ab ov e f u n c t i on s . Un l i k e Has k e l l0 码力 | 228 页 | 1.23 MB | 1 年前3
The Idris Tutorial Version 1.0.1m i l ar s y n t ax t o Has k e l l . Nat u r al n u m b e r s an d l i s t s , f or e x am p l e , c an b e d e c l ar e d as f ol l ow s : data Nat = Z | S Nat -- Natural numbers -- (zero and successor) ar d l i b r ar y : -- Unary addition plus : Nat -> Nat -> Nat plus Z y = y plus (S k) y = S (plus k y) -- Unary multiplication mult : Nat -> Nat -> Nat mult Z y = Z mult (S k) y = plus y (mult k y) t an d ar d ar i t h m e t i c op e r at or s + an d * ar e al s o ov e r l oad e d f or u s e b y Nat, an d ar e i m p l e m e n t e d u s i n g t h e ab ov e f u n c t i on s . Un l i k e Has k e l l0 码力 | 223 页 | 1.21 MB | 1 年前3
The Idris Tutorial Version 1.1.0m i l ar s y n t ax t o Has k e l l . Nat u r al n u m b e r s an d l i s t s , f or e x am p l e , c an b e d e c l ar e d as f ol l ow s : data Nat = Z | S Nat -- Natural numbers -- (zero and successor) ar d l i b r ar y : -- Unary addition plus : Nat -> Nat -> Nat plus Z y = y plus (S k) y = S (plus k y) -- Unary multiplication mult : Nat -> Nat -> Nat mult Z y = Z mult (S k) y = plus y (mult k y) t an d ar d ar i t h m e t i c op e r at or s + an d * ar e al s o ov e r l oad e d f or u s e b y Nat, an d ar e i m p l e m e n t e d u s i n g t h e ab ov e f u n c t i on s . Un l i k e Has k e l l0 码力 | 223 页 | 1.21 MB | 1 年前3
共 21 条
- 1
- 2
- 3













