# \[Solved\] Notty.term: signature error with a simple function

**URL:** <https://discuss.ocaml.org/t/solved-notty-term-signature-error-with-a-simple-function/1072>\
**Category:** Learning\
**Tags:** lwt, notty\
**Created:** [November 5, 2017, 6:43pm UTC](https://discuss.ocaml.org/t/solved-notty-term-signature-error-with-a-simple-function/1072 "2017-11-05T18:43:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cedlemo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/cedlemo/32/1213_2.png) [@cedlemo](https://discuss.ocaml.org/u/cedlemo)\
**Post date:** [November 5, 2017, 6:43pm UTC](https://discuss.ocaml.org/t/solved-notty-term-signature-error-with-a-simple-function/1072/1 "2017-11-05T18:43:29Z")

</div>

I have this simple code, that is a inspired from the [life.ml](https://github.com/pqwy/notty/blob/master/examples/life.ml) example of `Notty`. This idea is to create the simplest code possible that could illustrate:

- the creation of a Notty.term that is updated with a timeout
- the creation of 2 threads, one for the interface and one for another loop.

Here is the code:

```ocaml
(* ocamlfind ocamlc -o double_threads -package lwt,notty.lwt -linkpkg -g double_threads.ml*)
open Lwt
open Lwt.Infix
open Notty
open Notty_lwt
open Notty.Infix

module Term = Notty_lwt.Term

let counter = ref 0

let rec increase_counter () =
  (
    if !counter < max_int then counter := (!counter + 1)
    else counter := 0
  );
  Lwt.return ()
  >>= fun () ->
    increase_counter ()

let render (w, h) =
  I.(strf ~attr:A.(fg lightblack) "[counter %d]" !counter)

let timer () = Lwt_unix.sleep 0.1 >|= fun () -> `Timer

let event term = Lwt_stream.get (Term.events term) >|= function
  | Some (`Resize _ | #Unescape.event as x) -> x
  | None -> `End

let rec loop term (e, t) dim =
  (e <?> t) >>= function
  | `End | `Key (`Escape, []) ->
      Lwt.return_unit
  | `Timer ->
      Term.image term (render dim)
      >>= fun () ->
        loop term (e, timer ()) dim
  | `Mouse ((`Press _|`Drag), (x, y), _) ->
      loop term (event term, t) dim
  | `Resize dim' ->
      Term.image term (render dim')
      >>= fun () ->
        loop term (event term, t) dim
  | _ -> loop term (event term, t) dim

let interface () =
  let tc = Unix.(tcgetattr stdin) in
  Unix.(tcsetattr stdin TCSANOW { tc with c_isig = false });
  let term = Term.create () in
  let size = Term.size term in
  loop term (event term, timer ()) size

main () =
  Lwt.join [
    interface ();
    increase_counter ();
  ]

```

I get the following error when I compile it:

```auto
ocamlfind ocamlc -o double_threads -package lwt,notty.lwt -linkpkg -g double_threads.ml
File "double_threads.ml", line 51, characters 2-6:
Error: This function has type
         Term.t ->
         ([> `End
           | `Key of Notty.Unescape.key
           | `Mouse of Notty.Unescape.mouse
           | `Paste of Notty.Unescape.paste
           | `Resize of int * int
           | `Timer ]
          as 'a)
         Lwt.t * 'a Lwt.t -> int * int -> unit Lwt.t
       It is applied to too many arguments; maybe you forgot a `;'.

```

I have not been able to find where the problem is even with Merlin, I am sure that it is a stupid error but I can not find it.

---

<div class="post-metadata">

**Author:** ![hcarty](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/hcarty/32/1824_2.png) [@hcarty](https://discuss.ocaml.org/u/hcarty)\
**Post date:** [November 5, 2017, 7:10pm UTC](https://discuss.ocaml.org/t/solved-notty-term-signature-error-with-a-simple-function/1072/2 "2017-11-05T19:10:08Z")

</div>

I’m not sure if it’s an error from copying and pasting, but you’re missing a `let` in front of `main`.

---

<div class="post-metadata">

**Author:** ![ejgallego](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ejgallego/32/239_2.png) [@ejgallego](https://discuss.ocaml.org/u/ejgallego)\
**Post date:** [November 5, 2017, 7:11pm UTC](https://discuss.ocaml.org/t/solved-notty-term-signature-error-with-a-simple-function/1072/3 "2017-11-05T19:11:25Z")

</div>

Indeed, the missing let seems like the problem.

---

<div class="post-metadata">

**Author:** ![cedlemo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/cedlemo/32/1213_2.png) [@cedlemo](https://discuss.ocaml.org/u/cedlemo)\
**Post date:** [November 5, 2017, 7:45pm UTC](https://discuss.ocaml.org/t/solved-notty-term-signature-error-with-a-simple-function/1072/4 "2017-11-05T19:45:27Z")

</div>

@hcarty, @ejgallego,

okaayy 😅, it is time to do a break I guess. thanks
