function


Declaration of functions inside a module OCaml


So, i'am learning OCaml step by step and i've recently met the great world of "module langage" in OCaml.
Here is my problem:
module type TEST = sig
val addend : 'a -> list
end
module Test : TEST =
struct
let addend (val,lol) =
val::lol
end
when i try to use this inside the interpretor it tells me that i have a syntax error ...
I know that's this kind of anoying question asked by this guy who's a noob and thinks stack overflow is here to rewrite is poorly optimised code but still, after hours spend searching for a solution i've almost gived up at this point...
OCaml is cool, but why is it so hard.
First, in the definition of the type of your module : you have to specify the type of element of your list. You cannot use list alone.
The following code will compile :
module type TEST = sig
val addend : 'a -> 'a list
end;;
But will not do what you want as you want to define later a function that takes a element, a list and puts this element in this list.
So the signature of such function is :
'a -> 'a list -> 'a list
So the type of your module shall be :
module type TEST = sig
val addend : 'a -> 'a list -> 'a list
end;;
And the implementation :
module Test : TEST =
struct
let addend a l = a::l
end
;;
Please note that in your code, you may be influenced by C like language where you pass the arguments in parenthesis. In Ocaml, parenthesis are used for tuples ; this means that your implementation was different from the signature.
You get a syntax error becaue val is a keyword. You cannot use it as an identifier.

Related Links

in SAS proc fcmp how to get 2 numbers returned
How to input checkbox when used ng-table in Angular 2?
Coq: `Function … with` syntax
Why do they call them Thunks?
How can I assign an output to a function call in python?
Coq: Defining a function by pattern matching on the arity of its argument
Calling functions from other contracts solidity
How to write own List.map function in F#
Python3 Cannot concatenate error? How to fix?
Passing random type as parameter swift
Where is the mistake in this replacing function in Haskell?
TypeScript Mapped Type Key/Values
Haskell Instances required for definition
ERROR - Inferred type is not general enough
Avoid Subquery returned more than 1 value error in a table valued function
F# Finding lowest outcome of a function for all elements in a Sequence

Categories

HOME
react-native
centos
scadalts
ruby-on-rails-4
graphite
magento-1.9
asynchronous
rabbitmq
wildfly
scenekit
bootstrap-datepicker
axis2
graphviz
apigee
restcomm
business-objects
junit4
denial-of-service
postgresql-9.0
derivative
google-app-invites
ajaxform
entity-relationship
rubinius
navigation-drawer
interceptor
ext4
android-appbarlayout
autoload
pgadmin
na
kafka-python
omnipay
induction
hp-quality-center
quickbooks-online
netbanx-api
powerdns
youtube-analytics
regedit
homescreen
event-listeners
xilinx-edk
libphonenumber
auto-value
roc
burn
mosync
masm
django-media
google-keep
banking
siteminder
spring-java-config
code-signing-entitlements
android-runtime
launch-agent
cscore
smart-pointers
knox-gateway
python-wheel
sharepoint-userprofile
apple-watch-complication
devpartner
nscoding
zend-studio
sonarqube-5.4
eclipse-emf-ecore
singularitygs
bullseye
offsetheight
du
xamarin-forms
fileapi
bpopup
cpanm
drilldown
puphpet
treenode
code-completion
scrollviewer
zooming
componentkit
usleep
tracker
javascript-databinding
xcode-instruments
syntactic-sugar
casbah
deface
nools
qglviewer
avassetwriter
resourcedictionary
scite
mat-file
delphiscript
ipad-2
objectiveflickr
xemacs
plcrashreporter
google-doodle
layar
alasset
showmodaldialog
laconica
testing-strategies
flashlite

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile