Programming languages enthusiast. Author of Learn Type Driven Development: https://www.packtpub.com/application-development/learn-type-driven-development
Hi Alain, somehow I completely missed your comment here. Thanks for pointing out this error. Mistake on my part, can be fixed by swapping out the raise with failwith: | Error(err) => failwith({j|$err|j}) // Can't access data in this branch. raise expects something of type exn, but we are calling it with a string. We should use failwith instead which does take a string.
After that fix there is a second error, because the Node.Fs.readFileSync function doesn't actually take a nodeback. In my example I used a hypothetical function Node.Fs.readFile. I say hypothetical because it's not bound in the libraries shipped with BuckleScript, but of course fs.readFile is a real NodeJS function and you could write a binding fairly easily: nodejs.org/dist/latest-v10.x/docs/...
Thanks for taking the time, sir. I can't get this to run for whatever reason. I got this gist to run, gist.github.com/idkjs/c48dda9f1dba... but when i got to apply the concept, i keep running into problems. Even searched through your book! I will keep at it. Peace to you.
Programming languages enthusiast. Author of Learn Type Driven Development: https://www.packtpub.com/application-development/learn-type-driven-development
My apologies, I should have tested that example more thoroughly. I've now updated my previous comment with a really working code sample. You can run it like this:
Hi Alain, somehow I completely missed your comment here. Thanks for pointing out this error. Mistake on my part, can be fixed by swapping out the
raise
withfailwith
:| Error(err) => failwith({j|$err|j}) // Can't access data in this branch
.raise
expects something of typeexn
, but we are calling it with a string. We should usefailwith
instead which does take a string.After that fix there is a second error, because the
Node.Fs.readFileSync
function doesn't actually take a nodeback. In my example I used a hypothetical functionNode.Fs.readFile
. I say hypothetical because it's not bound in the libraries shipped with BuckleScript, but of coursefs.readFile
is a real NodeJS function and you could write a binding fairly easily: nodejs.org/dist/latest-v10.x/docs/...Anyway here's a full working example:
Thanks for taking the time, sir. I can't get this to run for whatever reason. I got this gist to run, gist.github.com/idkjs/c48dda9f1dba... but when i got to apply the concept, i keep running into problems. Even searched through your book! I will keep at it. Peace to you.
My apologies, I should have tested that example more thoroughly. I've now updated my previous comment with a really working code sample. You can run it like this: