Skip to content

Defining a foreign function #461

@ixmrm01

Description

@ixmrm01

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions