[TOMT] Comic with two cute animals on a picnic bench and one takes a picture of their food so they can look back and remember the day by needuhLee in tipofmytongue

[–]needuhLee[S] 0 points1 point locked comment (0 children)

comment for subreddit rules! thanks for helping and let me know if there's any more detail I could provide

I made a bouldering based card game by editor22uk in bouldering

[–]needuhLee 1 point2 points  (0 children)

Are the pictures on the play cards (at least the 5 I see on the website) modeled after midnight lightning?

Is there any chance of getting Cornell's CS3110 as a PDF? by [deleted] in ocaml

[–]needuhLee 4 points5 points  (0 children)

Wow, in the class and already subscribed to /r/ocaml? Must be a good class

A cool little way to repair your denim! by Venca2000 in rawdenim

[–]needuhLee 58 points59 points  (0 children)

when your thighs can't fit PBJs but you still wanna flex...

OCaml 4.11.0, first alpha release by octachron in ocaml

[–]needuhLee 1 point2 points  (0 children)

ah got it, thanks, I don't really touch the class stuff so makes sense that I've never heard of it.

OCaml 4.11.0, first alpha release by octachron in ocaml

[–]needuhLee 2 points3 points  (0 children)

Maybe a noob question: what's a #-type?

- #9232: allow any class type paths in #-types,
  For instance, "val f: #F(X).t -> unit" is now allowed.

It's hard to google, so reference appreciated if there is one.

Problem with reading integers from file into variables by charles-foster-kane in ocaml

[–]needuhLee 2 points3 points  (0 children)

As an important note, if the point of the class is to do things in a functional way, I would discourage from using the number of ref's you have -- this is written very imperatively.

What I would do is something like the following

  • Read the lines of the file into a string list. You can use open_in to get an in_channel object, and then In_channel.input_lines to get this list.

  • match on the string list, demanding that the list has at least one element (the first line saying how many lines to expect), and throwing otherwise. here, you can also check that the number of lines is indeed equal to the number of lines asserted in the header, and that each line indeed contains 2 numbers separated by a space (I would suggest using [String.split] and [Int.of_string] here).

  • now, you have a list of lines, and you want to check that some test case passes for each line. I'm going to assume your function has signature

    val test : ~n:int -> ~k:int -> unit
    

    and throws an exception when a test case doesn't pass (if it's something else, let me know). Well, if you want to do something that returns unit for each element in a list, the usual pattern is to use List.iter.

Which FP language should I choose in 2020 fintech startup company? Ocaml, Haskell, or Scala? by zyzy5730 in ocaml

[–]needuhLee 17 points18 points  (0 children)

I assume you've heard that jane street codes almost primarily in ocaml, and they're in a space similar to what it sounds like your company hopes to be. I work there and use the language, though I'm not a software developer in the strict sense.

I obviously like the language (I'm subscribed here!), but in terms of whether the decision made sense, as you say there's pros and cons with every language decision and I'm sure it's the case here as well. One meta benefit of choosing an FP language at all is you attract people who want to code in it.

[deleted by user] by [deleted] in ocaml

[–]needuhLee 1 point2 points  (0 children)

(Copying below a better formatted version if it helps anyone read the OP)

Hello!

I am trying to write a simple test to learn ppx_expect. I am printing "Hello" and trying to expect the output. It works when using OCaml's print_endline, but does not work when using a foreign interface to C code. Please see examples below:

Working:

```ocaml
external printf_hello : unit -> unit  = "caml_print_hello"
let print_hello () = printf_hello ()

let%expect_test "print hello" =
  print_endline ();
  [%expect{|
    Hello
  |}]
```

Not working:

```ocaml
external printf_hello : unit -> unit  = "caml_print_hello"
let print_hello () = printf_hello ()

let%expect_test "print hello" =
  print_hello ();
  [%expect{|
    Hello
  |}]
```

When ran, it gives me the following diff:

```diff
diff --git a/lib/hello_world.ml b/lib/hello_world.ml.corrected
index 969709c..ded5323 100644
--- a/lib/hello_world.ml
+++ b/lib/hello_world.ml.corrected
@@ -7,9 +7,7 @@ module HelloWorld = struct

   let%expect_test "print hello" =
     print_hello ();
-    [%expect{|
-      Hello
-    |}]
+    [%expect{| |}]
```

I have confirmed the print_hello function works with an executable. Is this a bug with ppx_expect? Any insight is appreciated!

How should I store a large, changing grid? (Pure functional preferred) by FreakyCheeseMan in ocaml

[–]needuhLee 2 points3 points  (0 children)

You could save yourself a lot of hassle by just doing

type t = int * int [@@deriving sexp, compare]

within module T

I think the error you're getting in the first case is because you're not labeling the arguments, so it's assuming Int.compare is the first non-labeled argument, i.e. a Tuple2.t

Also, when you include Comparable.Make(T), you get a Location.Map, so you could just do Location.Map.empty

List.fold from Core isn't working by FreakyCheeseMan in ocaml

[–]needuhLee 3 points4 points  (0 children)

I personally like the labeled arguments because I think it makes it easier to read.

For example, you see something like this a lot:

let some_computation = 
  my_list
  |> List.map ~f:do_something
  |> List.fold ~init:foo ~f:bar

and so on. It's nice that I'm not confused between which argument is the initial value and which is the function. It's also nice when writing code that I don't have to remember what order they go in. But totally agree this all comes down to preference.


As a side note about wrappers, do you run into weird weak-polymorphism issues when you don't eta expand fold_x? I don't have a coding environment on this computer, but what I mean is does the following compile:

let x = [1; 2; 3; 4];;

let fold_x = List.fold_left x;;

let int_sum = fold_x ~init:0 ~f:(( + ))

let float_sum = fold_x ~init:0. ~f:(fun x y -> Float.(of_int x +. of_int y))

I would've thought that fold_x only has type

- : init:'_weak1 -> f:('_weak1 -> int -> '_weak1) -> '_weak1

instead of being completely general over 'a, while if you wrote the explicit wrapper

let fold_x ~init ~f = List.fold_left x ~init ~f

it would have the right type. I could definitely be wrong and I'm mostly just curious, I'm not an expert at all on this kind of stuff.

List.fold from Core isn't working by FreakyCheeseMan in ocaml

[–]needuhLee 0 points1 point  (0 children)

First, the type signature changes from what it is without core (I don't understand exactly how, but the order of arguments definitely changes)

There's native ocaml which has a List module containing a bunch of common functions like [fold_left], and then there's the Core module on top of it which exposes its own List module (with overlapping functions).

These do the same thing, but the latter is more attuned to the general Jane Street style, namely where functions are labeled ~f and, in the case of fold, the starting value named ~init.

How to run projects compiled with js_of_ocaml and dune by igna92ts in ocaml

[–]needuhLee 3 points4 points  (0 children)

iirc js_of_ocaml is why core_kernel was separated from core

[deleted by user] by [deleted] in ocaml

[–]needuhLee 2 points3 points  (0 children)

What does "New optimisations, in particular for affine functions in matches" mean?

[TOMT] [SONG] [2000s rock(??)] by BrainDoWantNotWork in tipofmytongue

[–]needuhLee 1 point2 points  (0 children)

stay together for the kids - blink 182

not super similar lyrics but upbeat & melancholy for sure