当前位置:网站首页>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

边栏推荐
- QOpenGL显示点云文件
- Teach you how to use the reflect package to parse the structure of go - step 1: parameter type check
- [acnoi2022] not a structure, more like a structure
- 自动化测试的未来趋势
- WCF TCP protocol transmission
- Qmenu response in pyqt
- Promise的使用场景
- Markdown 实现文内链接跳转
- 05 Ubuntu installing mysql8
- Synthesize video through ffmpeg according to m3u8 file of video on the network
猜你喜欢

2021-03-16 COMP9021第九节课笔记

ZUCC_编译语言原理与编译_实验01 语言分析与简介

2021-03-04 comp9021 class 6 notes

搜索与推荐那些事儿

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

问题3 — messageBox弹框,修改默认背景色

Live broadcast review | detailed explanation of koordinator architecture of cloud native hybrid system (complete ppt attached)

根据网络上的视频的m3u8文件通过ffmpeg进行合成视频

Pat 1157: school anniversary

FPGA的虚拟时钟如何使用?
随机推荐
js滚动div滚动条到底部
WCF TCP protocol transmission
How to design a highly available and extended image storage function
Question 4 - datepicker date selector, disabling two date selectors (start and end dates)
将mysql的数据库导出xxx.sql,将xxx.sql文件导入到服务器的mysql中。项目部署。
Introduction to NC machine tool programming [G-code]
JVM underlying principle analysis
Question 3 - MessageBox pop-up box, modify the default background color
Getting started with ffmpeg
权限模型 DAC ACL RBAC ABAC
[introduction to point cloud dataset]
3D数学基础[十七] 平方反比定理
Fundamentals of 3D mathematics [17] inverse square theorem
VR is destined to reappear in the Jianghu?
11-- longest substring without repeated characters
新技术实战,一步步用Activity Results API封装权限申请库
Transformers pretrainedtokenizer class
Question bank and simulation examination for operation certificate of refrigeration and air conditioning equipment in 2022
App Startup
Catégorie de prêt 5