Post Aiac4MhmlEoz5XZL4S by deavmi@gleasonator.com
 (DIR) More posts by deavmi@gleasonator.com
 (DIR) Post #AiablbRxiS87JgDmRU by deavmi@gleasonator.com
       2024-06-04T16:27:59.274777Z
       
       0 likes, 0 repeats
       
       Exception handling is actually fun in OCaml, why? You guessed it, you can pattern match the exception types and then extract whatever from their actual definition.Updated the function I wrote yesterday to also close the file-descriptor once done.I could place more checks in as the open() may succeed but a read() may not and in such a case the file-descriptor would remain open. Another catch would be needed to wrap the read such that the fd name binding is still in scope and can be Unix.close()'d.The last improvement was needing to have the compiler not complain about what I returned. You need to return the same type of data everywhere - nothing better than a variant (tagged union) to solve that. The result/Result.t (latter forwards to the former) aids with that by having two distinct types that wrap a piece of data of any type (both union members have a single polymorphic type parameter).Anyways, long ramblings, it works :).#ocaml
       
 (DIR) Post #Aiac4MhmlEoz5XZL4S by deavmi@gleasonator.com
       2024-06-04T16:31:23.215284Z
       
       0 likes, 0 repeats
       
       d