Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining a foreign function #461

Open
ixmrm01 opened this issue Jul 21, 2021 · 0 comments
Open

Defining a foreign function #461

ixmrm01 opened this issue Jul 21, 2021 · 0 comments

Comments

@ixmrm01
Copy link

ixmrm01 commented Jul 21, 2021

Hello, I am missing something and/or I do not know how to compile it.

Commands I am using to create, compile and run my little test project:

$ mkdir saludos
$ cd saludos
$ hamler init
$ make
$ make run

My code:

saludos/src/Main.hm

module Main where

import Prelude
import Foreign (ffi2)
import English.Greetings as E
import Dutch.Groeten as D

main :: IO ()
main = do
 println (hola "Martin")
 println (E.hi "Martin")
 contents <- E.contents "Makefile"
 println (unir "3. Hi " contents)
 println (D.hoi "Martin")

hola :: String -> String
hola name = "1. Hola " ++ name ++ "!"

unir :: String -> String -> String
unir = ffi2 :string :concat


saludos/src/English/Greetings.hm

module English.Greetings (hi, contents) where

import Prelude
import Foreign (ffiIO1)
import System.Dir (FilePath)

hi :: String -> String
hi name = "2. Hi " ++ name ++ "!"

contents :: FilePath -> IO FilePath
contents = ffiIO1 :filename :absname


saludos/src/Dutch/Groeten.hm

module Dutch.Groeten (hoi) where

--foreign import hoi :: String -> String

import Prelude

hoi :: String -> String
hoi name = "4. Hoi " ++ name ++ "!"

My Erlang code that I would like to call instead of Groeten.hm

saludos/src/Dutch/Groeten.erl

-module('Groeten').

-export([hoi/1]).

-spec hoi(string()) -> string().
hoi(Name) -> string:concat("4. Hoi ", Name).
@ixmrm01 ixmrm01 changed the title Calling a custom Erlang function Defining a foreign function Jul 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant