SlideShare a Scribd company logo
(* hogeは int lazy_t 型 *)
let hoge = lazy 1
$ cat test_ocaml.ml
let hoge = lazy 1 + 2
$ omake
*** omake: reading OMakefiles
*** omake: finished reading OMakefiles (0.01 sec)
- build . test_ocaml.cmi
+ ocamlfind ocamlopt -package oUnit -warn-error A -annot 
 -I . -c test_ocaml.ml
File "test_ocaml.ml", line 1, characters 11-17:
Error: This expression has type int lazy_t
       but an expression was expected of type int




let hoge = (lazy 1) + 2
(* hogeは int lazy_t 型 *)
let hoge = lazy (1 + 2)




let rec map f s = lazy (match s with
  | (lazy SSnil) -> SSnil
  | (lazy (SScons(x, s))) -> SScons(f x, map f s))
$ cat test_ocaml.ml
let hoge = lazy (1 + 2)

let _ = print_int (Lazy.force hoge)
(* (Lazy.force hoge) は Int 型 *)
$ ./test_ocaml
3
$ cat test_ocaml.ml
let hoge = lazy (1 + 2)

let _ = match hoge with
  | lazy i -> print_int i
$ ./test_ocaml
3
let plus (lazy m) (lazy n) = lazy (m + n)




let _ = let i = Lazy.force (plus (lazy 1) (lazy 2)) in
         print_int i
fun lazy plus ($m, $n) = $m+n



fun plus (x, y) = $case (x, y) of ($m, $n) => force ($m+n)




(* plus : int lazy_t -> int lazy_t -> int lazy_t *)
let plus m n = lazy(match (m, n) with
  | (lazy m, lazy n) -> m + n)
datatype a StreamCell = NIL | CONS of a * a Stream
withtype a Stream = a StreamCell susp



type 'a cell = SSnil | SScons of 'a * 'a stream
and 'a stream = 'a cell Lazy.t
fun lazy ($NIL) ++ t = t
     | ($CONS (x, s)) ++ t = $CONS (x, s ++ t)



let rec (++) t1 t2 = lazy (match (t1, t2) with
  | (lazy SSnil, lazy t2) -> t2
  | (lazy (SScons(x, s)), t2) -> SScons(x, s ++ t2))
fun lazy take (0, s) = $NIL
     | take (n, $NIL) = $NIL
     | take (n, $CONS (x, s)) = $CONS (x, take (n - 1, s))



let rec take n s = lazy (match (n, s) with
  | (0, _) -> SSnil
  | (_, lazy SSnil) -> SSnil
  | (n, lazy (SScons(x, s))) -> SScons(x, take (n - 1) s))
fun lazy drop (n, s) =
 let fun drop' (0, s) = s
      | drop' (n, $NIL) = $NIL
      | drop' (n, $CONS (x, s)) = drop' (n - 1, s)
 in drop' (n, s) end



let drop n s = lazy (
  let rec drop' n s = match (n, s) with
    | (0, lazy s) -> s
    | (_, lazy SSnil) -> SSnil
    | (n, lazy (SScons(_, s))) -> drop' (n - 1) s
  in drop' n s)
fun lazy reverse s =
 let fun reverse' ($NIL, r) = r
      | reverse' ($CONS (x, s), r) = reverse' (s, $CONS (x, r))
 in reverse' (s, $NIL) end



let reverse s = lazy (
  let rec reverse' s r = match (s, r) with
    | (lazy SSnil, r) -> r
    | (lazy (SScons(x, s)), r) -> reverse' s (lazy (SScons(x, r)))
  in Lazy.force (reverse' s (lazy SSnil)))
https://github.com/master-q/
readPurelyFunctionalDataStructures/
tree/master/LazyEvaluation

More Related Content

What's hot

言語の設計判断
言語の設計判断言語の設計判断
言語の設計判断
nishio
 
Print input-presentation
Print input-presentationPrint input-presentation
Print input-presentation
Martin McBride
 
Control de acceso con excel
Control de acceso con excelControl de acceso con excel
Control de acceso con excel
Reember Alex Arteaga Ticona
 
Oprerator overloading
Oprerator overloadingOprerator overloading
Oprerator overloading
Parthipan Parthi
 
PHP 101
PHP 101 PHP 101
PHP 101
Muhammad Hijazi
 
正規表現のいろは
正規表現のいろは正規表現のいろは
正規表現のいろは
Ayumu Hanba
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
Ke Wei Louis
 
The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)
GroovyPuzzlers
 
Python built in functions
Python built in functionsPython built in functions
Python built in functions
Rakshitha S
 
Polynomials
PolynomialsPolynomials
Polynomials
Jonghoon Park
 
Tabla derivadas
Tabla derivadasTabla derivadas
Tabla derivadas
a99carlitos
 
SAT/SMT solving in Haskell
SAT/SMT solving in HaskellSAT/SMT solving in Haskell
SAT/SMT solving in Haskell
Masahiro Sakai
 

What's hot (12)

言語の設計判断
言語の設計判断言語の設計判断
言語の設計判断
 
Print input-presentation
Print input-presentationPrint input-presentation
Print input-presentation
 
Control de acceso con excel
Control de acceso con excelControl de acceso con excel
Control de acceso con excel
 
Oprerator overloading
Oprerator overloadingOprerator overloading
Oprerator overloading
 
PHP 101
PHP 101 PHP 101
PHP 101
 
正規表現のいろは
正規表現のいろは正規表現のいろは
正規表現のいろは
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)
 
Python built in functions
Python built in functionsPython built in functions
Python built in functions
 
Polynomials
PolynomialsPolynomials
Polynomials
 
Tabla derivadas
Tabla derivadasTabla derivadas
Tabla derivadas
 
SAT/SMT solving in Haskell
SAT/SMT solving in HaskellSAT/SMT solving in Haskell
SAT/SMT solving in Haskell
 

Viewers also liked

Functional IoT: Introduction
Functional IoT: IntroductionFunctional IoT: Introduction
Functional IoT: Introduction
Kiwamu Okabe
 
Functional IoT: Hardware and Platform
Functional IoT: Hardware and PlatformFunctional IoT: Hardware and Platform
Functional IoT: Hardware and Platform
Kiwamu Okabe
 
Functional IoT: Programming Language and OS
Functional IoT: Programming Language and OSFunctional IoT: Programming Language and OS
Functional IoT: Programming Language and OS
Kiwamu Okabe
 
Macrodown -MLが使えるML-
Macrodown -MLが使えるML-Macrodown -MLが使えるML-
Macrodown -MLが使えるML-
T. Suwa
 
Embedded application designed by ATS language
Embedded application designed by ATS languageEmbedded application designed by ATS language
Embedded application designed by ATS language
Kiwamu Okabe
 
線形型のある言語でLEDを光らせる
線形型のある言語でLEDを光らせる線形型のある言語でLEDを光らせる
線形型のある言語でLEDを光らせる
啓 小笠原
 
Real-time OS system state captured by ATS language
Real-time OS system state captured by ATS languageReal-time OS system state captured by ATS language
Real-time OS system state captured by ATS language
Kiwamu Okabe
 
Does Infer dream of design by contract?
Does Infer dream of design by contract?Does Infer dream of design by contract?
Does Infer dream of design by contract?
Kiwamu Okabe
 
Emacs verilog-mode is coming to Debian, again
Emacs verilog-mode is coming to Debian, againEmacs verilog-mode is coming to Debian, again
Emacs verilog-mode is coming to Debian, again
Kiwamu Okabe
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學
littlebtc
 

Viewers also liked (10)

Functional IoT: Introduction
Functional IoT: IntroductionFunctional IoT: Introduction
Functional IoT: Introduction
 
Functional IoT: Hardware and Platform
Functional IoT: Hardware and PlatformFunctional IoT: Hardware and Platform
Functional IoT: Hardware and Platform
 
Functional IoT: Programming Language and OS
Functional IoT: Programming Language and OSFunctional IoT: Programming Language and OS
Functional IoT: Programming Language and OS
 
Macrodown -MLが使えるML-
Macrodown -MLが使えるML-Macrodown -MLが使えるML-
Macrodown -MLが使えるML-
 
Embedded application designed by ATS language
Embedded application designed by ATS languageEmbedded application designed by ATS language
Embedded application designed by ATS language
 
線形型のある言語でLEDを光らせる
線形型のある言語でLEDを光らせる線形型のある言語でLEDを光らせる
線形型のある言語でLEDを光らせる
 
Real-time OS system state captured by ATS language
Real-time OS system state captured by ATS languageReal-time OS system state captured by ATS language
Real-time OS system state captured by ATS language
 
Does Infer dream of design by contract?
Does Infer dream of design by contract?Does Infer dream of design by contract?
Does Infer dream of design by contract?
 
Emacs verilog-mode is coming to Debian, again
Emacs verilog-mode is coming to Debian, againEmacs verilog-mode is coming to Debian, again
Emacs verilog-mode is coming to Debian, again
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學
 

Similar to PFDS 4章をOCamlに翻訳

Lambda calculus
Lambda calculusLambda calculus
Lambda calculus
Attila Magyar
 
Pdfcode
PdfcodePdfcode
Send + More = Money – Let’s mash 2 monads to solve a simple CSP
Send + More = Money – Let’s mash 2 monads to solve a simple CSPSend + More = Money – Let’s mash 2 monads to solve a simple CSP
Send + More = Money – Let’s mash 2 monads to solve a simple CSP
Filippo Vitale
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
ikdysfm
 
BOXPLOT EXAMPLES in R And An Example for BEESWARM:
BOXPLOT EXAMPLES in R And  An Example for BEESWARM:BOXPLOT EXAMPLES in R And  An Example for BEESWARM:
BOXPLOT EXAMPLES in R And An Example for BEESWARM:
Dr. Volkan OBAN
 
{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発Tips{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発Tips
Takashi Kitano
 
Crea un archivo pdf en escala de grises que permite búsquedas 1
Crea un archivo pdf en escala de grises que permite búsquedas 1Crea un archivo pdf en escala de grises que permite búsquedas 1
Crea un archivo pdf en escala de grises que permite búsquedas 1
Luis Carlos Balcazar
 
PFDS 9.2.3 Lazy Representations
PFDS 9.2.3 Lazy RepresentationsPFDS 9.2.3 Lazy Representations
PFDS 9.2.3 Lazy Representations
昌平 村山
 
Shell and perl scripting classes in mumbai
Shell and perl scripting classes in mumbaiShell and perl scripting classes in mumbai
Shell and perl scripting classes in mumbai
Vibrant Technologies & Computers
 
FYP Final Presentation
FYP Final PresentationFYP Final Presentation
FYP Final Presentation
Jason Yeo Jie Shun
 
matlab codes.pdf
matlab codes.pdfmatlab codes.pdf
matlab codes.pdf
EdysaulCondorhuancar
 
Артём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data AnalysisАртём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data Analysis
SpbDotNet Community
 
OTLN2012
OTLN2012OTLN2012
OTLN2012
KEITH SMITH
 
Perl6 one-liners
Perl6 one-linersPerl6 one-liners
Perl6 one-liners
Andrew Shitov
 
Oh Composable World!
Oh Composable World!Oh Composable World!
Oh Composable World!
Brian Lonsdorf
 
Agda であそぼ
Agda であそぼAgda であそぼ
Agda であそぼ
erutuf13
 
Implementing Software Machines in C and Go
Implementing Software Machines in C and GoImplementing Software Machines in C and Go
Implementing Software Machines in C and Go
Eleanor McHugh
 
Ch5b.ppt
Ch5b.pptCh5b.ppt
Ch5b.ppt
MDSayem35
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
kesav24
 
Scope Graphs: A fresh look at name binding in programming languages
Scope Graphs: A fresh look at name binding in programming languagesScope Graphs: A fresh look at name binding in programming languages
Scope Graphs: A fresh look at name binding in programming languages
Eelco Visser
 

Similar to PFDS 4章をOCamlに翻訳 (20)

Lambda calculus
Lambda calculusLambda calculus
Lambda calculus
 
Pdfcode
PdfcodePdfcode
Pdfcode
 
Send + More = Money – Let’s mash 2 monads to solve a simple CSP
Send + More = Money – Let’s mash 2 monads to solve a simple CSPSend + More = Money – Let’s mash 2 monads to solve a simple CSP
Send + More = Money – Let’s mash 2 monads to solve a simple CSP
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
BOXPLOT EXAMPLES in R And An Example for BEESWARM:
BOXPLOT EXAMPLES in R And  An Example for BEESWARM:BOXPLOT EXAMPLES in R And  An Example for BEESWARM:
BOXPLOT EXAMPLES in R And An Example for BEESWARM:
 
{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発Tips{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発Tips
 
Crea un archivo pdf en escala de grises que permite búsquedas 1
Crea un archivo pdf en escala de grises que permite búsquedas 1Crea un archivo pdf en escala de grises que permite búsquedas 1
Crea un archivo pdf en escala de grises que permite búsquedas 1
 
PFDS 9.2.3 Lazy Representations
PFDS 9.2.3 Lazy RepresentationsPFDS 9.2.3 Lazy Representations
PFDS 9.2.3 Lazy Representations
 
Shell and perl scripting classes in mumbai
Shell and perl scripting classes in mumbaiShell and perl scripting classes in mumbai
Shell and perl scripting classes in mumbai
 
FYP Final Presentation
FYP Final PresentationFYP Final Presentation
FYP Final Presentation
 
matlab codes.pdf
matlab codes.pdfmatlab codes.pdf
matlab codes.pdf
 
Артём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data AnalysisАртём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data Analysis
 
OTLN2012
OTLN2012OTLN2012
OTLN2012
 
Perl6 one-liners
Perl6 one-linersPerl6 one-liners
Perl6 one-liners
 
Oh Composable World!
Oh Composable World!Oh Composable World!
Oh Composable World!
 
Agda であそぼ
Agda であそぼAgda であそぼ
Agda であそぼ
 
Implementing Software Machines in C and Go
Implementing Software Machines in C and GoImplementing Software Machines in C and Go
Implementing Software Machines in C and Go
 
Ch5b.ppt
Ch5b.pptCh5b.ppt
Ch5b.ppt
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
 
Scope Graphs: A fresh look at name binding in programming languages
Scope Graphs: A fresh look at name binding in programming languagesScope Graphs: A fresh look at name binding in programming languages
Scope Graphs: A fresh look at name binding in programming languages
 

Recently uploaded

HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Things to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUUThings to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUU
FODUU
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
CAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on BlockchainCAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on Blockchain
Claudio Di Ciccio
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 

Recently uploaded (20)

HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Things to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUUThings to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUU
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
CAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on BlockchainCAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on Blockchain
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 

PFDS 4章をOCamlに翻訳

  • 1.
  • 2.
  • 3. (* hogeは int lazy_t 型 *) let hoge = lazy 1
  • 4. $ cat test_ocaml.ml let hoge = lazy 1 + 2 $ omake *** omake: reading OMakefiles *** omake: finished reading OMakefiles (0.01 sec) - build . test_ocaml.cmi + ocamlfind ocamlopt -package oUnit -warn-error A -annot -I . -c test_ocaml.ml File "test_ocaml.ml", line 1, characters 11-17: Error: This expression has type int lazy_t but an expression was expected of type int let hoge = (lazy 1) + 2
  • 5. (* hogeは int lazy_t 型 *) let hoge = lazy (1 + 2) let rec map f s = lazy (match s with | (lazy SSnil) -> SSnil | (lazy (SScons(x, s))) -> SScons(f x, map f s))
  • 6. $ cat test_ocaml.ml let hoge = lazy (1 + 2) let _ = print_int (Lazy.force hoge) (* (Lazy.force hoge) は Int 型 *) $ ./test_ocaml 3
  • 7. $ cat test_ocaml.ml let hoge = lazy (1 + 2) let _ = match hoge with | lazy i -> print_int i $ ./test_ocaml 3
  • 8. let plus (lazy m) (lazy n) = lazy (m + n) let _ = let i = Lazy.force (plus (lazy 1) (lazy 2)) in print_int i
  • 9. fun lazy plus ($m, $n) = $m+n fun plus (x, y) = $case (x, y) of ($m, $n) => force ($m+n) (* plus : int lazy_t -> int lazy_t -> int lazy_t *) let plus m n = lazy(match (m, n) with | (lazy m, lazy n) -> m + n)
  • 10.
  • 11. datatype a StreamCell = NIL | CONS of a * a Stream withtype a Stream = a StreamCell susp type 'a cell = SSnil | SScons of 'a * 'a stream and 'a stream = 'a cell Lazy.t
  • 12. fun lazy ($NIL) ++ t = t | ($CONS (x, s)) ++ t = $CONS (x, s ++ t) let rec (++) t1 t2 = lazy (match (t1, t2) with | (lazy SSnil, lazy t2) -> t2 | (lazy (SScons(x, s)), t2) -> SScons(x, s ++ t2))
  • 13. fun lazy take (0, s) = $NIL | take (n, $NIL) = $NIL | take (n, $CONS (x, s)) = $CONS (x, take (n - 1, s)) let rec take n s = lazy (match (n, s) with | (0, _) -> SSnil | (_, lazy SSnil) -> SSnil | (n, lazy (SScons(x, s))) -> SScons(x, take (n - 1) s))
  • 14. fun lazy drop (n, s) = let fun drop' (0, s) = s | drop' (n, $NIL) = $NIL | drop' (n, $CONS (x, s)) = drop' (n - 1, s) in drop' (n, s) end let drop n s = lazy ( let rec drop' n s = match (n, s) with | (0, lazy s) -> s | (_, lazy SSnil) -> SSnil | (n, lazy (SScons(_, s))) -> drop' (n - 1) s in drop' n s)
  • 15. fun lazy reverse s = let fun reverse' ($NIL, r) = r | reverse' ($CONS (x, s), r) = reverse' (s, $CONS (x, r)) in reverse' (s, $NIL) end let reverse s = lazy ( let rec reverse' s r = match (s, r) with | (lazy SSnil, r) -> r | (lazy (SScons(x, s)), r) -> reverse' s (lazy (SScons(x, r))) in Lazy.force (reverse' s (lazy SSnil)))