{"id":18552896,"url":"https://github.com/oderwat/nim-haskell-ffi","last_synced_at":"2025-11-01T09:30:29.535Z","repository":{"id":27354635,"uuid":"30829876","full_name":"oderwat/nim-haskell-ffi","owner":"oderwat","description":null,"archived":false,"fork":false,"pushed_at":"2015-02-15T14:40:34.000Z","size":136,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-15T06:17:32.020Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oderwat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-15T14:36:46.000Z","updated_at":"2023-04-22T07:35:48.000Z","dependencies_parsed_at":"2022-09-02T07:22:15.712Z","dependency_job_id":null,"html_url":"https://github.com/oderwat/nim-haskell-ffi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oderwat%2Fnim-haskell-ffi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oderwat%2Fnim-haskell-ffi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oderwat%2Fnim-haskell-ffi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oderwat%2Fnim-haskell-ffi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oderwat","download_url":"https://codeload.github.com/oderwat/nim-haskell-ffi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239278510,"owners_count":19612329,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T21:15:28.420Z","updated_at":"2025-11-01T09:30:29.460Z","avatar_url":"https://github.com/oderwat.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nim-Haskell FFI Example\n\n**(aka: Calling Nim from Haskell)**\n\nAs Nim can compile to libraries and I am also interested in some Haskell I thought I could try to call some Nim from Haskell.\n\n_This was largely inspired by the \"[Rust-Haskell FFI Example](https://github.com/aisamanra/rust-haskell-ffi)\"_ and handles just the fact() case from the Rust example.\n\nAt first I just wanted to get it running and simply duplicated the example for an unsigned integer factorial function.\n\nAfter getting more compfortable I may extend this to more complicated types.\n\n# How it works\n\nBasically I just compile the Nim source with some special compiler flags to a static library and let GHC link against it. The Haskell FFI does the rest.\n\nTo check that out you need a working Haskell compiler. I assume you have already if you read this :)\n\nSecond you need the [Nim Compiler](http://nim-lang.org/). It is free and probably the start of a long term love.\n\nAfter that run `make \u0026\u0026 ./fact` which should output:\n\n```\nfact(20) = 2432902008176640000\n```\n\nThis also is the largest factorial this proc can handle.\n\n\u003e If Haskell calls Nim with 21 it will segfault. If you run that with the Nim compiler (`nim c -r fact.nim`) you will see how Nim generates an exeption for the overflow.\n\n_For more info look at the various sources. I may update this repository with more stuff later._\n\n# Mac OS X specials\n\nCompiling to a static library  with `clang` calls `llvm-ar` which seems not to be installed on OS X.\n\nCompiling with `clang` worked after I simply added a softlink to the system `ar` like this:\n\n```\nls -s /usr/bin/ar /usr/local/bin/llvm-ar\n```\n\nUsing `--cc=GCC` to compile the lib worked after I removed the `-fasm-blocks` from `/etc/nim.cfg`. This has to go anyway imho!\n\nThats all so far! Have fun with Nim!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foderwat%2Fnim-haskell-ffi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foderwat%2Fnim-haskell-ffi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foderwat%2Fnim-haskell-ffi/lists"}