ããã Zenn ã®ãã¼ã¯ãã¦ã³ã¨ãã£ã¿ããã¡ããã¡ãæ ¼å¥½è¯ããªã£ã¦ãã¾ãï¼ãæé«ï¼ï¼ Inline styling ã£ã¦ç¸å½é£ããããããªãã§ãããã
Preface About This Book Installing OCaml Introduction 1. Better Programming Through OCaml 1.1. The Past of OCaml 1.2. The Present of OCaml 1.3. Look to Your Future 1.4. A Brief History of CS 3110 1.5. Summary 2. The Basics of OCaml 2.1. The OCaml Toplevel 2.2. Compiling OCaml Programs 2.3. Expressions 2.4. Functions 2.5. Documentation 2.6. Printing 2.7. Debugging 2.8. Summary 2.9. Exercises OCaml
OCaml ã¯ç¾æç¹ã§ãã«ãã³ã¢å¯¾å¿ãããªãã®ã§ããã«ãã¹ã¬ããã«ãã¦ããã«ãã³ã¢ã®æ©æµã享åãããã¨ãã§ãã¾ãããã§ãã®ã§ãOCaml 㧠thread ã使ãæ¨ã¿ã¨ããã®ã¯ãé¢æ°ã並è¡ã«èµ°ãããäºãã§ããã£ã¦ãã¨ã ãã§ããã§ã並è¡ã«èµ°ãããäºãåºæ¥ãã°ãããã便å©ã§ãããã ã§ããã«ãã¹ã¬ããããã°ã©ãã³ã°ã§ä¸çªå°ãã®ãæä»å¶å¾¡ããããä¸æããã£ã¦ãããªãã¨ãOCaml 㧠type safe ãªã¯ããªã®ã«ã segfault ã¨ããäºã«ãªãã¾ãããã¡ãã OCaml ããã°ã©ãã¯æ®æ®µãã type safety ã«æ £ããã£ã¦ããã®ã§ã type system ã§ä¿éãããªãæä»å¶å¾¡ãå®ç§ã«æ¸ããã¯ãããªãã®ã§ããå¿ãæãã¾ãã ããã§ãlight weight threadãããã¤ã¯å®ã¯ thread ããããã¾ãããè¦ã¯åä¸ã¹ã¬ããå ã§ã¿ã¹ã¯é¢æ°ãã¨ã£ããã²ã£ãã asynchro
List, Array, Record ãªã©ã®è¦ç´ åºåãã® ; ã¯ã¨ã¦ãå¥å¦ã«è¦ãããããããªãã OCaml ã使ã£ã¦ãã人ã§ããã¾ãæèãã¦ããªãã®ã ããå®ã¯ä¸è²«æ§ãããã A ; B 㯠B ; A ã¨æ¸ãã¦ãåã¯å¤ãããªã A , B 㯠B , A ã¨æ¸ãã¨åãå¤ããå ´åããã ä¾: print_string "hello"; print_string "world" { a = 42; b = "hello" } [ 1; 2; 3 ] [| 1; 2; 3 |] ãããã®è¦ç´ ãå ¥ãæ¿ãã¦ãåã¯å¤ãããªãããã¡ããæå³ã¯å¤ããå ´åãããã ä¾: (1, "hello") (int, float) Hashtbl.t ãããã®è¦ç´ ãå ¥ãæ¿ããã¨åãå¤ãã£ã¦ãã¾ãã
ãã®è¨äºã¯ML Advent Calendar 2021 5æ¥ç®ã®è¨äºã§ãã OCamlã®ã©ãã«ä»ãå¼æ°ãç´¹ä»ãã¾ãã åç½®ã éçåä»ãè¨èªã®å©ç¹ã®ã²ã¨ã¤ã¨ãã¦ãåãè¦ãã°ãªãã¨ãªãå¦çã®å 容ã®æ³åãã¤ãã¨ããç¹ãããã 'a -> 'a list -> boolã§ããã°ãªã¹ãã«å¤ãå«ã¾ãããå¤å®ããé¢æ°ã ãããã('a -> bool) -> 'a list -> 'a optionã§ããã°ãªã¹ãããè¿°èªãæºããå¤ãè¦ã¤ããé¢æ°ã ãããstring -> string list -> stringã ã¨æ¢ç´¢é¢æ°ã£ã½ããããããã©ãæååã®ãªã¹ãã®çµåé¢æ°ããªã¨ããæ°ãããï¼ã¡ãªã¿ã«ãããã¯ããããæ¨æºã©ã¤ãã©ãªã®List.memã¾ãã¯List.memqãList.find_optãString.concatã®åã ï¼ã ã¨ã¯ãããã®ã®ããã«ãéçããããåãåã®å¼æ°ãè¤æ°åããããªé¢æ°ã«ãª
ç®æ¬¡ ï¼ç« ãã¯ããã« åæ© åå¥è§£æã¨æ§æ解æ lex 㨠yacc æ¬æ¸ã®æ§æ ï¼ç« ãå¼ãç®é»å 対象è¨èª å¼ãç®è¨èªã§ä½¿ãããåå¥ï¼ãã¼ã¯ã³ï¼ å¼ãç®è¨èªã®ææ³ ä¾ ãã¡ã¤ã«ã®æ§æ æ§ææ¨ã®å®ç¾© åå¥è§£æãã¡ã¤ã« è£å©çãªå¤æ°ãé¢æ°ãåã®å®ç¾© æ£è¦è¡¨ç¾ã®ç¥è¨ åå¥è§£æã®è¦å æ§æ解æãã¡ã¤ã« è£å©çãªå¤æ°ãé¢æ°ãåã®å®ç¾© å種ã®å®ç¾©ã¨å®£è¨ ãã¼ã¯ã³ã®å®ç¾© ã¨ã³ããªã¼ãã¤ã³ãï¼éå§è¨å·ï¼ã®æå® éçµç«¯è¨å·ã®åã®æå® æ¼ç®åã®çµåè¦åã¨åªå é ä½ã®æå® æ§æ解æã®è¦åï¼ææ³ï¼ ã¡ã¤ã³ãã¡ã¤ã« å¼ãç®é»åã®å¦ç ã³ã³ãã¤ã«ã®æ¹æ³ èªåã§ã³ã³ãã¤ã«ããæ¹æ³ dune ã使ãæ¹æ³ OCamlMakefile ã使ãæ¹æ³ ï¼ç« ãshift/reduce conflict ææ³ãææ§ãã©ããã®ãã§ã㯠æ§æ解æ表ã®èªã¿æ¹ çµåè¦åã«ããææ§æ§ã®è§£æ¶ åªå é ä½ã«ããææ§æ§ã®è§£æ¶ %prec ã«ããåªå é
OCaml ã§å®è£ ããæ¼ç®åã®å®ç¾©ãã§ããçµã¿è¾¼ã¿ã® Result åãããparser ã®å¤±æãæ¤ç¥ããå¿ è¦ãããå¼æ°ã®é©ç¨ãããããã俺㯠Haskell ãæ¸ããªã Parser ã®å®ç¾©type input = { text : string; pos : int } type parser_t = input -> input * ('a, string) result; å ¥å ãåãåããæ¶è²»ããªãã£ãå ¥åã¨ããã¼ã¹çµæãè¿ãã æ¶è²»ããªãã£ãå ¥åãè¿ãã®ã¯ãå¾ç¶ã® parser ã«æ¸¡ãããã ä¾: æå°éã®ãã¼ãµã¼ æååã®å é ä¸æåããã¼ã¹ããã let get_char = function | [] -> None | c::cs -> Some (c, cs) FYI: https://zehnpaard.hatenablog.com/entry/2019/07/05/
é¢æ°åããã°ã©ãã³ã°è¨èª OCaml ã® GADTs (Generalized Algebraic Datatypes) ã«é¢ãã¦ãä½ã¨ãªãæå³è«ãæ³åããªãããµã³ãã«ã³ã¼ããåçµãã¦ã¿ã¦ãå ¨ç¶ãã£ããããªãã£ãã®ã§ãããã£ããã¨ã¨çåç¹ãã¾ã¨ãã¦ãããã¨æãã¾ãã
OCaml ã®ã1ã¢ã¸ã¥ã¼ã«1ãã¼ã¿åã¹ã¿ã¤ã«ãããã®ããã°ã©ãã³ã°ã¹ã¿ã¤ã«ã¯21ä¸ç´ã«å ¥ã£ã¦ããã¢ã¸ã¥ã¼ã«ãå¤ç¨ãã OCaml ã³ãã¥ããã£ã§æµè¡ãã ãããã®ã§ç§ãæ¡ç¨ãã¦ãã¾ããæºæµã¯ SML æ¹é¢ã«ããã¨èãã¾ãããâ¦ç§èªä¿¡ã¯ç¢ºèªãã¦ãã¾ãããè¦åºå ¸ã§ãã ã1ã¢ã¸ã¥ã¼ã«1ãã¼ã¿åã¹ã¿ã¤ã«ãã®æå³ããã¨ããã¯ç°¡åã§ã: ãã¼ã¿åä¸ã¤ä¸ã¤ã«ã¢ã¸ã¥ã¼ã«ãä¸ã¤ä¸ã¤ä½ãã ã¢ã¸ã¥ã¼ã«åã¯åã®æå³ããååãã¤ããã人ãªã Personã ã¢ã¸ã¥ã¼ã«å ã§å®ç¾©ãããã¼ã¿åã¯å¸¸ã« t ã¨ããæ½è±¡çãªååã«ããã t ã主対象ã¨ããæä½ã¯ã¢ã¸ã¥ã¼ã«å ã§å®ç¾©ããã ãã ããå ¨ã¦ã® OCaml ããã°ã©ã ã¯ãã®ããã«æ¸ãããã¹ããã¨ãããã®ã§ãããã¾ããã ä¾ãã°ã OCaml ã®ã³ã³ãã¤ã©ã®ã½ã¼ã¹ã³ã¼ãã¯ãã®ã¹ã¿ã¤ã«ã§ã¯å ¨ãæ¸ããã¦ãã¾ããã ã1ã¢ã¸ã¥ã¼ã«1ãã¼ã¿åã¹ã¿ã¤ã«ãã®å©ç¹ã¯: ã¢ã¸ã¥ã¼ã«å
ExamplesBelow is a simple example of setting a key and getting the value out of a Git based, filesystem-backed store. open Lwt.Syntax (* Irmin store with string contents *) module Store = Irmin_git_unix.FS.KV(Irmin.Contents.String) (* Database configuration *) let config = Irmin_git.config ~bare:true "/tmp/irmin/test" (* Commit author *) let author = "Example " (* Commit information *) let info fm
Building Functional SystemsOur solutions help developers build robust, secure, high-performance applications whilst maintaining crucial reliability. Custom Development ServicesCustom development of software components and tailor-made tools In-house consultancy services to increase the efficiency of your teams and promote best practices Training, code review and advice on OCaml technologies Open So
Edit Quick and Dirty Guide to Monadic Parsers and Angstrom Author: Metin Akat @loxs Review: Ivan Gotovchits @ivg Abstract This tutorial aims to give you abilities to write parsers quickly for your daily tasks. Itâs not a formal or academic explanation of parsers, grammars, monads etc. On the contrary, it aims to be as informal as possible and to have as little requirements for previous knowledge a
æåã«ä»¥ä¸ã®ãªã³ã¯ã®ãããããä¸èªãããã¨ããªã¹ã¹ã¡ãã¾ãã Real World OCaml ã«è¨è¼ããã¦ããæ¹æ³ Installation Instructions OCaml Programming: Correct + Efficient + Beautiful ã«è¨è¼ããã¦ããæ¹æ³ Installing OCaml â OCaml Programming: Correct + Efficient + Beautiful 京é½å¤§å¦å·¥å¦é¨å°éç§ç®ãããã°ã©ãã³ã°è¨èªå¦çç³»ãè¬ç¾©è³æ OCaml å¦çç³»ã®ã¤ã³ã¹ãã¼ã« OPAM ã®ã¤ã³ã¹ãã¼ã« OPAM ã¨ã¯ OCaml PAckage Manager ããã±ã¼ã¸ããã¼ã¸ã£ã ãã©ãOCamlæ¬ä½ãOPAMãéãã¦ã¤ã³ã¹ãã¼ã«ã§ãã ãªã®ã§æåã«OPAMãå ¥ãã OPAMã®ã¤ã³ã¹ãã¼ã«æã«OCamlãå ¥ãããç¹ã«é¢ä¿ãªã Mac ãªã b
ããã°ã©ã ã®é¨åã ããOCaml ã§ã¯ ã¹ãã©ã¯ãã£ã¨å¼ã¶ã OCamlã®ã©ã¤ãã©ãªã¯å ¨ã¦ã¢ã¸ã¥ã¼ã«ï¼ã¹ãã©ã¯ãã£ï¼ã¨ãã¦æä¾ãããã ãã¡ã¤ã«åãã¢ã¸ã¥ã¼ã«å example.ml ã¨ãããã¡ã¤ã«åãâãExample ã¨ããã¢ã¸ã¥ã¼ã«ã æ¨æºã¢ã¸ã¥ã¼ã« OCamlçµã¿è¾¼ã¿ã®ã¢ã¸ã¥ã¼ã«é¡ (* ãªã¹ã *) # List.length [1; 2; 3];; - : int = 3 # let q = Queue.create ();; val q : '_a Queue.t = <abstr> (* ãã¥ã¼ *) # Queue.add "first" q;; - : unit = () # Queue.take q;; - : string = "first" # Queue.take q;; Exception: Queue.Empty. (* é å *) # Array.make
ãã®è¨äºã¯ ML Advent Calendar 2020 ã®14æ¥ç®ã®è¨äºã§ãï¼ ãªã¹ãã® Church encoding ã¨è¨ãã° List.fold_right ã§è¡¨ç¾ãããã¨ãå¤ãããã«æãã¾ããï¼æãã㦠List.fold_right ã ããã使ããã«æ§ã ãªãªã¹ãã«ã¤ãã¦ã®å帰é¢æ°ã表ç¾ã§ããã®ãçåã«æã人ãå¤ãã®ã§ã¯ãªãã§ããããï¼ æ¬è¨äºã§ã¯ï¼List.fold_right ãç¨ã㦠List.fold_left ãå®è£ ããæ¹æ³ãç´¹ä»ãã¾ãï¼å¾è ã¯æ«å°¾å帰ãªã®ã§ããããåããã©ããã¨ãããã«ç´æ¥ä½¿ã£ãæ¹ãè¯ãã®ã¯ãã£ã¨ããªã®ã§ããï¼foldr/build ãªãããèããæã«é ã®çé ã«ããã¨ä¾¿å©ããããã¾ããï¼ List.fold_right 㨠List.fold_left OCaml æ¨æºã©ã¤ãã©ãªã§æä¾ããã¦ãã List.fold_right ã¨ã¯èªãã§åã®ãã¨ããª
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}