当前位置:网站首页>ZUCC_ Principles of compiling language and compilation_ Experiment 02 fsharp Ocaml language
ZUCC_ Principles of compiling language and compilation_ Experiment 02 fsharp Ocaml language
2022-06-24 08:30:00 【The stars don't want to roll】
Compiling language principle and compiling experiment report
| Course name | Compiling language principle and compiling |
|---|---|
| Experimental projects | FSharp OCaml Language |
The experiment purpose
- master FSharp、OCaml The history of language development
- Programming ML The type system of a family of languages 、 Control structure
Experimental content
1、Rider Installation and F# Project creation
Rider download
https://www.jetbrains.com/zh-cn/rider/

New empty project

Download and install Mono
https://www.mono-project.com/download/stable/#download-mac

function Appendix.fs Script code
val it: int = 7
val res: int = 7
val it: int = 14
val y: float = 1.414213562
val z: float = 1.414213562
val large: bool = false
val it: bool = false
val it: bool = true
val it: int = 117
val title: string = "Prof."
val name: string = "Lauesen"
val junkmail: string = "Dear Prof. Lauesen, You won $$$!"
val it: int = 32
val circleArea: r: float -> float
val a: float = 314.1592654
val mul2: x: float -> float
val it: float = 7.0
val makejunk: title: string -> name: string -> string
val it: string = "Dear Vice Chancellor Tofte, You won $$$!"
val fac: n: int -> int
val it: int = 5040
val even: n: int -> bool
val odd: n: int -> bool
val isLarge: x: float -> bool
val it: bool = true
val x: int = 42
val r: int = 625
val it: int = 42
val facm: n: int -> int
val faca: _arg1: int -> int
val p: int * int = (2, 3)
val w: int * bool * float * string = (2, true, 3.4, "blah")
val add: x: int * y: int -> int
val it: int = 5
val noon: int * int = (12, 0)
val talk: int * int = (15, 15)
val earlier:
('a * 'b) * ('a * 'b) -> bool when 'a: comparison and 'b: comparison
Hello!
val it: unit = ()
val x1: int list = [7; 9; 13]
val x2: int list = [7; 9; 13]
val equal: bool = true
val ss: string list = ["Dear"; "Prof."; "Lauesen"; "you won $$$!"]
val junkmail2: string = "Dear Prof. Lauesen you won $$$!"
val sum: xs: int list -> int
val x2sum: int = 29
val prod: xs: int list -> int
val x2prod: int = 819
val len: xs: 'a list -> int
val x2len: int = 3
val sslen: int = 4
val x3: int list = [47; 11]
val x1x3: int list = [7; 9; 13; 47; 11]
type phonerec =
{
name: string
phone: int
}
val ph: phonerec = { name = "Kasper"
phone = 5170 }
val it: string = "Kasper"
val it: int = 5170
exception IllegalHour
val mins1: h: int -> int
FSI_0061+IllegalHour: Exception of type 'FSI_0061+IllegalHour' was thrown.
at FSI_0062.mins1(Int32 h)
at <StartupCode$FSI_0063>[email protected]()
Stopped due to error
val it: int = -1
val mins2: h: int -> int
System.Exception: Illegal hour
at FSI_0065.mins2(Int32 h)
at <StartupCode$FSI_0066>[email protected]()
Stopped due to error
val mins3: h: int -> int
System.Exception: Illegal hour, h=25
at [email protected]439.Invoke(String message) in D:\a\_work\1\s\src\fsharp\FSharp.Core\printf.fs:line 1439
at <StartupCode$FSI_0068>[email protected]()
Stopped due to error
type person =
| Student of string
| Teacher of string * int
val people: person list = [Student "Niels"; Teacher ("Peter", 5083)]
val getphone1: person: person -> int
System.Exception: no phone
at FSI_0071.getphone1(person person)
type intopt =
at <StartupCode$FSI_0072>[email protected]()
| Some of int
Stopped due to error
| None
val getphone2: person: person -> intopt
val it: intopt = None
type inttree =
| Lf
| Br of int * inttree * inttree
val t1: inttree = Br (34, Br (23, Lf, Lf), Br (54, Lf, Br (78, Lf, Lf)))
val sumtree: t: inttree -> int
val t1sum: int = 189
val addp: x: int * y: int -> int
val addc: x: int -> y: int -> int
val res1: int = 42
val res2: int = 42
val addSeventeen: (int -> int)
val res3: int = 42
val res4: int = 117
val len: xs: 'a list -> int
val it: int = 3
val it: int = 4
type 'a tree =
| Lf
| Br of 'a * 'a tree * 'a tree
val t1: int tree = Br (34, Br (23, Lf, Lf), Br (54, Lf, Br (78, Lf, Lf)))
val sumtree: t: int tree -> int
val count: t: 'a tree -> int
val preorder1: t: 'a tree -> 'a list
val it: int list = [34; 23; 54; 78]
val preo: t: 'a tree -> acc: 'a list -> 'a list
val preorder2: t: 'a tree -> 'a list
type intenv = (string * int) list
val bind1: env: intenv -> x: string * v: int -> intenv
val it: intenv = [("phone", 5083); ("age", 47)]
val map: f: ('a -> 'b) -> xs: 'a list -> 'b list
val mul2: x: float -> float
val it: float list = [8.0; 10.0; 178.0]
val it: bool list = [false; false; true]
val it: x: float -> float
val it: float list = [8.0; 10.0; 178.0]
val it: bool list = [false; false; true]
val tw: g: ('a -> 'a) -> x: 'a -> 'a
val quad: (float -> float)
val it: float = 28.0
val it: x: int -> y: int -> int
val it: x: int -> y: int -> int
val increaseBoth: i: int -> x: int * y: int -> int * int
val isZeroFirst: _arg1: int list -> bool
val filter: p: ('a -> bool) -> xs: 'a list -> 'a list
val onlyEven: int list = [4; 6; 2; 54]
let v = !r;;
val foldr: f: ('a -> 'b -> 'b) -> xs: 'a list -> e: 'b -> 'b
--------^
val len: xs: 'a list -> int
val sum: xs: int list -> int
val prod: xs: int list -> int
val map: g: ('a -> 'b) -> xs: 'a list -> 'b list
val listconcat: xss: 'a list list -> 'a list
val stringconcat: xss: string list -> string
/Users/owem/Desktop/Profession/FSharp/ConsoleApplication1/stdin(388,9): info FS3370: The use of '!' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change '!cell' to 'cell.Value'.
val filter: p: ('a -> bool) -> xs: 'a list -> 'a list
val r: int ref = { contents = 177 }
r := 288;;
--^^
val v: int = 177
/Users/owem/Desktop/Profession/FSharp/ConsoleApplication1/stdin(390,3): info FS3370: The use of ':=' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change 'cell := expr' to 'cell.Value <- expr'.
val it: unit = ()
val it: int = 288
!r;;
^
val nextlab: int ref = { contents = -1 }
/Users/owem/Desktop/Profession/FSharp/ConsoleApplication1/stdin(392,1): info FS3370: The use of '!' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change '!cell' to 'cell.Value'.
val newLabel: unit -> string
val it: string = "L0"
let newLabel () = (nextlab := 1 + !nextlab; "L" + string (!nextlab));;
---------------------------^^
val it: string = "L1"
/Users/owem/Desktop/Profession/FSharp/ConsoleApplication1/stdin(396,28): info FS3370: The use of ':=' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change 'cell := expr' to 'cell.Value <- expr'.
val it: string = "L2"
val arr: int[] = [|2; 5; 7|]
let newLabel () = (nextlab := 1 + !nextlab; "L" + string (!nextlab));;
----------------------------------^
val it: int = 5
/Users/owem/Desktop/Profession/FSharp/ConsoleApplication1/stdin(396,35): info FS3370: The use of '!' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change '!cell' to 'cell.Value'.
val it: unit = ()
val it: int[] = [|2; 11; 7|]
let newLabel () = (nextlab := 1 + !nextlab; "L" + string (!nextlab));;
----------------------------------------------------------^
val it: int = 3
/Users/owem/Desktop/Profession/FSharp/ConsoleApplication1/stdin(396,59): info FS3370: The use of '!' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change '!cell' to 'cell.Value'.
2、F# The sample code
QuickSort
let rec quicksort list =
match list with
| [] -> // If the list is empty
[] // return an empty list
| firstElem::otherElements -> // If the list is not empty
let smallerElements = // extract the smaller ones
otherElements
|> List.filter (fun e -> e < firstElem)
|> quicksort // and sort them
let largerElements = // extract the large ones
otherElements
|> List.filter (fun e -> e >= firstElem)
|> quicksort // and sort them
// Combine the 3 parts into a new list and return it
List.concat [smallerElements; [firstElem]; largerElements]
//test
printfn $"%A{quicksort [1;5;23;18;9;1;3]}"

Deep First Search
type Tree<'a> =
| Empty
| Node of value: 'a * left: Tree<'a> * right: Tree<'a>
let traverse (tree : Tree<'a>) =
let rec loop (tree : Tree<'a>) = seq {
match tree with
| Empty -> ()
| Node (value, left, right) ->
yield value
yield! loop left
yield! loop right
}
loop tree
let tree =
Node (1,
Node (2,
Node (4, Empty, Empty),
Node (5, Empty, Empty)),
Node (3,
Node (6,
Node (7, Empty, Empty),
Empty),
Node (8, Empty, Empty)))
// 1
// / \
// 2 3
// / \ / \
// 4 5 6 8
// /
// 7
traverse tree |> Seq.iter (printfn "%d") // 1 2 4 5 3 6 7 8

边栏推荐
- Industrial computer anti cracking
- Several ways you can't move zero (sequel)
- The article takes you to understand the security of Windows operating system and protect your computer from infringement
- Optimization and practice of Tencent cloud EMR for cloud native containerization based on yarn
- js滚动div滚动条到底部
- Robot acceleration level task priority inverse kinematics
- 2022茶艺师(中级)上岗证题库及在线模拟考试
- Scénarios d'utilisation de la promesse
- 独立站运营中如何提升客户留存率?客户细分很重要!
- SQL intra statement operation
猜你喜欢

2021-03-11 COMP9021第八节课笔记

Question bank and simulation examination for operation certificate of refrigeration and air conditioning equipment in 2022

Synthesize video through ffmpeg according to m3u8 file of video on the network

Qt导出PDF文件的两种方法

2022年流动式起重机司机特种作业证考试题库及在线模拟考试

The article takes you to understand the security of Windows operating system and protect your computer from infringement

About the iframe anchor, the anchor is offset up and down, and the anchor has page display problems Srcdoc problem of iframe

Markdown to realize text link jump

Search and recommend those things

Introduction to RCNN, fast RCNN and fast RCNN
随机推荐
13 -- 移除无效的括号
貸款五級分類
论文笔记: 多标签学习 DM2L
Solution of electric education system for intelligent supervision station
Live broadcast review | detailed explanation of koordinator architecture of cloud native hybrid system (complete ppt attached)
根据网络上的视频的m3u8文件通过ffmpeg进行合成视频
问题4 — DatePicker日期选择器,2个日期选择器(开始、结束日期)的禁用
一文带你了解Windows操作系统安全,保护自己的电脑不受侵害
How to implement approval function in Tekton
2021-03-16 comp9021 class 9 notes
PAT 1157:校庆
2021-03-11 COMP9021第八节课笔记
pyQt 常用系统的事件
App Startup
Opencv get (propid) common values
MAYA重新拓布
问题3 — messageBox弹框,修改默认背景色
Export MySQL database to xxx SQL, set xxx The SQL file is imported into MySQL on the server. Project deployment.
js滚动div滚动条到底部
11-- longest substring without repeated characters