{"id":17740604,"url":"https://github.com/rusq/gohaskell","last_synced_at":"2025-04-21T07:33:02.841Z","repository":{"id":104033722,"uuid":"412007154","full_name":"rusq/gohaskell","owner":"rusq","description":"Example of calling Haskell Function from Go program (using C interface)","archived":false,"fork":false,"pushed_at":"2021-09-30T09:51:42.000Z","size":3,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T18:08:38.432Z","etag":null,"topics":["c","example","golang","haskell","interface","lulz","tutorial"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rusq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-30T09:44:03.000Z","updated_at":"2025-03-06T17:12:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"1de18869-2086-4b86-a068-025eb331b816","html_url":"https://github.com/rusq/gohaskell","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/rusq%2Fgohaskell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rusq%2Fgohaskell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rusq%2Fgohaskell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rusq%2Fgohaskell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rusq","download_url":"https://codeload.github.com/rusq/gohaskell/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250014809,"owners_count":21361017,"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":["c","example","golang","haskell","interface","lulz","tutorial"],"created_at":"2024-10-26T03:06:44.033Z","updated_at":"2025-04-21T07:33:02.617Z","avatar_url":"https://github.com/rusq.png","language":"Go","readme":"# Calling Haskell From Go Example\n\u003e I did it for the lulz.\n\n\u003ca rel=\"license\" href=\"http://creativecommons.org/licenses/by-sa/4.0/\"\u003e\u003cimg alt=\"Creative Commons License\" style=\"border-width:0\" src=\"https://i.creativecommons.org/l/by-sa/4.0/88x31.png\" /\u003e\u003c/a\u003e\u003cbr /\u003eThis work is licensed under a \u003ca rel=\"license\" href=\"http://creativecommons.org/licenses/by-sa/4.0/\"\u003eCreative Commons Attribution-ShareAlike 4.0 International License\u003c/a\u003e.\n\n## Building\n\n#### Updating the source paths\nMake sure to update the libraries path in `main.go` on the line\n```\n// #cgo LDFLAGS: Safe.o -L \u003c...\u003e -lHSbase-4.14.3.0 -lHSinteger-gmp-1.0.3.0 -lHSghc-prim-0.6.1 -lHSrts -lCffi -liconv -lm -ldl\n```\n\n`-l` parameters should remain - they specify the required Haskell libraries\nfor linking.  You may need to update the libraries versions.\n\n#### Easy (Makefile)\nRun:\n```\nmake\n```\nand it should do the job.\n\n#### Manual build\n```\nghc -c -O Safe.hs\ngo build\n```\n\n## If something goes wrong\nMost likely some libraries are missing or not specified in `main.go`.\n\nTo verify which libraries and paths are in use on your system, follow the steps below.\n\nPaste this source to a file named `test.c`\n```c\n#include \u003cHsFFI.h\u003e\n#ifdef __GLASGOW_HASKELL__\n#include \"Safe_stub.h\"\n#endif\n#include \u003cstdio.h\u003e\n\nint main(int argc, char *argv[])\n{\n    int i;\n    hs_init(\u0026argc, \u0026argv);\n\n    i = fibonacci_hs(42);\n    printf(\"Fibonacci: %d\\n\", i);\n\n    hs_exit();\n    return 0;\n}\n```\n\nRun:\n\n```sh\nghc -c -O Safe.hs\nghc --make -no-hs-main -v -optc-O test.c Safe -o test\n```\nThis will generate the compile and link commands for your version of C compiler.\nCheck the output and use it as the guidance, and let the sun enlighten your treacherous path.\n\n## References\n\nBased on the following materials:\n* [Calling Haskell From C](https://wiki.haskell.org/Calling_Haskell_from_C)\n* [Go: passing argv to C function](https://stackoverflow.com/questions/37657326/go-passing-argv-to-c-function)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frusq%2Fgohaskell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frusq%2Fgohaskell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frusq%2Fgohaskell/lists"}