简体   繁体   中英

Unit testing for uncurry in ocaml

my implementation so far I cant seem to understand where is the issue

let uncurry_test1 _test_ctxt =
    assert_equal
    uncurry  f  (4 3)
    7
    

The assert_equal function from the OUnit2 library has type,

val assert_equal :
  ?ctxt:test_ctxt ->
  ?cmp:('a -> 'a -> bool) ->
  ?printer:('a -> string) ->
  ?pp_diff:(Format.formatter -> ('a * 'a) -> unit) ->
  ?msg:string -> 'a -> 'a -> unit

There are only two non-keyword parameters, but you're applying it to four. I would suggest you read at least the OCaml tutorial and learn how functions are applied in OCaml. For example, the piece of code (4 3) in OCaml means apply 4 to 3 , where "apply F to Y" means call the function F with argument X. Obviously, 4 is not a function (spoiler, it is a number), so this code doesn't make sense and raises a type error.

It is hard to guess from the information that you provided what is the type of uncurry and what is the type of f , but probably you meant something like this,

assert_equal 7 (uncurry f 4 3)

Which says, that we expect 7 when we uncurry the function f and apply it to 4 and 3 .

where f is probably curry (+)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM