Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I call a Haskell function from Golang?

Tags:

haskell

go

ffi

I am a python developer making the shift to Golang, so I'm sorry for the noob question. I am responsible for taking some Haskell code, for which we have python bindings, and making it callable from Go. I have a shared object file, _foo.so, that I want to somehow import into Go and call a la:

import (
    f "_foo.so"
)

func DoBar() {
    return f.Bar()
}

Is this possible? I don't even have the first idea of where to begin, but I'm hoping that pseudo code gets the idea across.

like image 325
TayTay Avatar asked Dec 20 '19 15:12

TayTay


1 Answers

As already mentioned in the comments, you need to go through C.

Good news: the python binding you have goes through C already. It means that haskell code exposes all the necessary API as C functions, you just need to find out how the API looks like and call it using cgo. You probably don't need to know anything about haskell.

Assuming you have access to the source code, you should look for *.c and *.h files (often located in a cbits folder). If you don't know C, then ask your teammates to help.

If you don't have access to the code, then you may try to guess the C API using the python binding. Though it'll be quite hard.

like image 150
Yuras Avatar answered Sep 25 '22 12:09

Yuras