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

边栏推荐
- Four models of iPhone 13 series have been exposed, and indeed, they are 13 fragrant!
- io模型初探
- App Startup
- Chart list Performance Optimization: minimum resource consumption in the visualization area
- More appropriate development mode under epidemic situation
- 2021-06-25: a batch of strings consisting only of lowercase letters (a~z) are put
- Synthesize video through ffmpeg according to m3u8 file of video on the network
- Question 1: the container that holds the most water
- 问题4 — DatePicker日期选择器,2个日期选择器(开始、结束日期)的禁用
- 疫情下更合适的开发模式
猜你喜欢

Qt导出PDF文件的两种方法

C language_ Love and hate between string and pointer

Search and recommend those things

Longhorn installation and use

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

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

Question 3 - MessageBox pop-up box, modify the default background color

2021-03-04 COMP9021第六节课笔记

【无标题】

More appropriate development mode under epidemic situation
随机推荐
Opening chapter of online document technology - rich text editor
2022茶艺师(中级)上岗证题库及在线模拟考试
transformers PreTrainedTokenizer类
Five level classification of loans
Saccadenet: use corner features to fine tune the two stage prediction frame | CVPR 2020
C language_ Love and hate between string and pointer
Review SGI STL secondary space configurator (internal storage pool) | notes for personal use
11--无重复字符的最长子串
PAT 1157:校庆
Introduction to RCNN, fast RCNN and fast RCNN
MAYA重新拓布
RCNN、Fast-RCNN、Faster-RCNN介绍
Maya re deployment
Four models of iPhone 13 series have been exposed, and indeed, they are 13 fragrant!
【无标题】
Promise的使用场景
longhorn安装与使用
QOpenGL显示点云文件
io模型初探
Small sample fault diagnosis - attention mechanism code - Implementation of bigru code parsing