Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Haskell
Wiki community
Recent changes
Random page
HaskellWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Yhc/Erlang/Proof of concept
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Erlang calling Haskell=== From the point of view adopted in this experiment, calls of Haskell functions from Erlang are rare. This mostly happens when a Haskell application compiled for Erlang VM is started; so a predefined function like <hask>main</hask> is invoked. From the Erlang standpoint, Haskell functions are just regular functions. It is however good to observe few rules: * Haskell objects are not always identical to Erlang objects. For example, while numbers may be passed as they are, lists need to be wrapped in tagged tuples. Some Erlang objects do not have exact mapping to Haskell objects. * Haskell programs are compiled with respect to function type signatures defined in the source code (or inferred during compilation). Haskell functions do not contain code to check types of values passed as arguments. Haskell function compiled to receive integer values will behave unpredictably when given a string or a list of integers as its argument. * It is strongly recommended to export from Haskell modules only functions that take values of monomorphic types. That is, type signature <hask>Int -> String</hask> is OK while <hask>(Num a) => a -> String</hask> is not. For the latter function to work correctly, additional argument should be passed which is a proper class dictionary. Dictionaries are nearly impossible to export as Haskell functions; they will be assigned numeric identifiers unrecognizable at Erlang side. * Due to non-strict nature of Haskell, it is recommended to wrap call to a function exported from a Haskell-originated module in <code>hserl:force</code> if a function returns numeric value or an atom, or <code>hserl:hslist</code>, if a function returns a list (e. g. a String): * It is sometimes advisable not to try to call a Haskell function with its arguments directly, but to form a thunk (an Erlang tuple tagged with ''@ap'') instead, including function's name and arguments, and apply <code>hserl:force</code> or <code>hserl:hslist</code> to the thunk. Necessity of using <code>hserl:force</code> or <code>hserl:hslist</code> when calling Haskell functions from Erlang is illustrated below: <code> 3> hs_test1:fuse({'@lst', "ABCDE"}, {'@lst', "123"}). {'@dt','.CONS',65, {'@dt','.CONS',49, {'@ap',{hs_test1,fuse},2,[{'@lst',"BCDE"},{'@lst',"23"}]}}} 4> hserl:hslist(hs_test1:fuse({'@lst', "ABCDE"}, {'@lst', "123"})). "A1B2C3DE" </code> When <code>hserl:hslist</code> was not applied, the function returns a portion of a Haskell list, and a recursive application of the same function to process the rest of source lists. When <code>hserl:hslist</code> is applied, returned value is as expected: elements of the two lists are interleaved together.
Summary:
Please note that all contributions to HaskellWiki are considered to be released under simple permissive license (see
HaskellWiki:Copyrights
for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel
Editing help
(opens in new window)
Toggle limited content width