ocaml

Why there is no binary distribution for OCaml on Win64? [closed]

孤街醉人 提交于 2019-12-23 06:35:47
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . The OCaml download page is announcing that there is four Windows ports available: Cygwin, Mingw, native Win32, and native Win64. However the latest one is in fact not available and must be compiled from sources only. Given that the Windows/x86_64 port has been done since a

OCaml - Reverse a list

筅森魡賤 提交于 2019-12-23 04:02:56
问题 I'm trying to implement my own list module as follows : type 'a my_list = | Item of ('a * 'a my_list) | Empty I've already implemented several functions and am now trying to create a list reversing function for my module which would look like this : let rec rev = function | Empty -> (*return reversed list*) | Item(i, remnant) -> (*recursive call to rev*) Moreover, I'm not supposed to use list operators such as '::', '[]' and '@'. Edit, what I tried : let rec rev_append l1 l2 = match l1 with |

OCaml - Reverse a list

雨燕双飞 提交于 2019-12-23 04:02:27
问题 I'm trying to implement my own list module as follows : type 'a my_list = | Item of ('a * 'a my_list) | Empty I've already implemented several functions and am now trying to create a list reversing function for my module which would look like this : let rec rev = function | Empty -> (*return reversed list*) | Item(i, remnant) -> (*recursive call to rev*) Moreover, I'm not supposed to use list operators such as '::', '[]' and '@'. Edit, what I tried : let rec rev_append l1 l2 = match l1 with |

The correct way to build a Binary Search Tree in OCaml

﹥>﹥吖頭↗ 提交于 2019-12-23 03:59:06
问题 Ok, I have written a binary search tree in OCaml. type 'a bstree = |Node of 'a * 'a bstree * 'a bstree |Leaf let rec insert x = function |Leaf -> Node (x, Leaf, Leaf) |Node (y, left, right) as node -> if x < y then Node (y, insert x left, right) else if x > y then Node (y, left, insert x right) else node The above code was said to be good in The right way to use a data structure in OCaml However, I found a problem. This insert will only work when building a bst from a list in one go, such as

SystemT Compiler and dealing with Infinite Types in Haskell

跟風遠走 提交于 2019-12-22 09:20:09
问题 I'm following this blog post: http://semantic-domain.blogspot.com/2012/12/total-functional-programming-in-partial.html It shows a small OCaml compiler program for System T (a simple total functional language). The entire pipeline takes OCaml syntax (via Camlp4 metaprogramming) transforms them to OCaml AST that is translated to SystemT Lambda Calculus (see: module Term ) and then finally SystemT Combinator Calculus (see: module Goedel ). The final step is also wrapped with OCaml

Suggestion for solving fragile pattern matching

左心房为你撑大大i 提交于 2019-12-22 08:52:12
问题 I often need to match a tuple of values that should have the same constructor. The catchall _,_ always winds-up at the end. This of course is fragile, any additional constructor added to the type will compile perfectly fine. My current thoughts are to have matches that connect the first but not second argument. But, is there any other options? For example, type data = | States of int array | Chars of (char list) array let median a b = match a,b with | States xs, States ys -> assert( (Array

OCaml literal negative number?

不羁的心 提交于 2019-12-22 06:33:18
问题 I'm learning. This is something I found strange: let test_treeways x = match x with | _ when x < 0 -> -1 | _ when x > 0 -> 1 | _ -> 0;; If I then call it like this: test_threeways -10;; I will get type mismatch error (because, as far as I understand, it interprets unary minus as if it was partial function application, so it considers the type of the expression to be int -> int . However, this: test_threeways (-10);; acts as expected (though this actually calculates the value, as I could

Linear types in OCaml

我的未来我决定 提交于 2019-12-22 06:09:09
问题 Rust has a linear type system. Is there any (good) way to simulate this in OCaml? E.g., when using ocaml-lua, I want to make sure some functions are called only when Lua is in a specific state (table on top of stack, etc). Edti : Here's a recent paper about resource polymorphism relevant to the question: https://arxiv.org/abs/1803.02796 回答1: As suggested by John Rivers, you can use a monadic style to represent "effectful" computation in a way that hides the linear constraint in the effect API

Resolving reduce/reduce conflict in yacc/ocamlyacc

丶灬走出姿态 提交于 2019-12-22 03:52:40
问题 I'm trying to parse a grammar in ocamlyacc (pretty much the same as regular yacc) which supports function application with no operators (like in Ocaml or Haskell), and the normal assortment of binary and unary operators. I'm getting a reduce/reduce conflict with the '-' operator, which can be used both for subtraction and negation. Here is a sample of the grammar I'm using: %token <int> INT %token <string> ID %token MINUS %start expr %type <expr> expr %nonassoc INT ID %left MINUS %left APPLY

Resolving reduce/reduce conflict in yacc/ocamlyacc

谁说胖子不能爱 提交于 2019-12-22 03:52:10
问题 I'm trying to parse a grammar in ocamlyacc (pretty much the same as regular yacc) which supports function application with no operators (like in Ocaml or Haskell), and the normal assortment of binary and unary operators. I'm getting a reduce/reduce conflict with the '-' operator, which can be used both for subtraction and negation. Here is a sample of the grammar I'm using: %token <int> INT %token <string> ID %token MINUS %start expr %type <expr> expr %nonassoc INT ID %left MINUS %left APPLY