10 Replies - 16583 Views - Last Post: 27 July 2015 - 09:10 AM

#1 macosxnerd101  Icon User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 11334
  • View blog
  • Posts: 42,745
  • Joined: 27-December 08

Week 42- OCaml

Post icon  Posted 01 December 2010 - 03:31 PM

Posted Image

This week's challenge is Objective Caml, the most popular variant of the Caml language. OCaml combines the Object-Oriented, Imperative, and Functional paradigms, along with static typing to help reduce problems at runtime. It also has type-inference, so one does not need to explicitly declare data types in method signatures or variables.

Some of OCaml's other features include:
  • Parametric polymorphism
  • Tail recursion
  • Pattern matching
  • First class lexical closures
  • Functors
  • Exception handling
  • Automated garbage collection


Getting Started and Resources
OCaml Homepage
Download Compilers
OCaml plugin for Eclipse
Ocaml-tutorial.org
FFConsultancy OCaml Tutorial

Is This A Good Question/Topic? 0
  • +

Replies To: Week 42- OCaml

#2 Raynes  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 614
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Re: Week 42- OCaml

Posted 02 December 2010 - 07:56 AM

OCaml is a neat language. Note that, if you so desired, you could also cheat and use F#. F# is a very, very similar language based off of OCaml.
Was This Post Helpful? 0
  • +
  • -

#3 g4143  Icon User is offline

  • New D.I.C Head

Reputation: 15
  • View blog
  • Posts: 46
  • Joined: 30-April 09

Re: Week 42- OCaml

Posted 27 July 2015 - 01:41 AM

You forgot to mention OCaml's greatest feature. Its type system which guarantees a seg-fault free program if the program will compile.

Other interesting features are currying and partial function evaluation. Here's a example of partial function evaluation.

type func_params =
	| Three_Params of (string -> string -> string -> unit)
	| Two_Params of (string -> string -> unit)
	| One_Params of (string -> unit)

let display_strings a b c =
	print_endline(a ^ " " ^ b ^ " " ^ c)

let funcRef = ref(Three_Params display_strings)

let get_hello c =
	if c < 10
	then
		Some(string_of_int c ^ " :Hello")
	else
		None

let get_func_str pf str =
	match !pf with
	| Three_Params p -> Two_Params(p str)
	| Two_Params p -> One_Params (p str)
	| One_Params p -> p str; Three_Params display_strings

let hlines = Stream.from get_hello;;

try
	while true do
		funcRef := get_func_str funcRef (Stream.next hlines)
	done
with
| Stream.Failure -> ()

let get_remainder pf =
	match !pf with
	| Three_Params p -> p "1:Padding" "2:Padding" "3:Padding"
	| Two_Params p -> p "1:Padding" "2:Padding"
	| One_Params p -> p "1:Padding";;

get_remainder funcRef;;



OCaml is a great but difficult language that's not really mainstream but its used a lot in research.
Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 6292
  • View blog
  • Posts: 13,456
  • Joined: 16-October 07

Re: Week 42- OCaml

Posted 27 July 2015 - 05:00 AM

Dude! You're necroing all the weeks of code? :P

It should be noted that in the nearly five years since this post, a version of OCaml is now probably about as mainstream as a language can get. F# is a fully supported .NET language.
Was This Post Helpful? 0
  • +
  • -

#5 g4143  Icon User is offline

  • New D.I.C Head

Reputation: 15
  • View blog
  • Posts: 46
  • Joined: 30-April 09

Re: Week 42- OCaml

Posted 27 July 2015 - 06:57 AM

View Postbaavgai, on 27 July 2015 - 06:00 AM, said:

Dude! You're necroing all the weeks of code? :P/>


Yeah I suffer from the new and stupid syndrome.
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 11334
  • View blog
  • Posts: 42,745
  • Joined: 27-December 08

Re: Week 42- OCaml

Posted 27 July 2015 - 07:32 AM

We left the 52 Weeks of Code Challenges open so folks could participate later if they chose. Feel free to necro if you wish to participate in them. :)
Was This Post Helpful? 0
  • +
  • -

#7 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 8744
  • View blog
  • Posts: 15,051
  • Joined: 19-March 11

Re: Week 42- OCaml

Posted 27 July 2015 - 08:33 AM

View Postbaavgai, on 27 July 2015 - 07:00 AM, said:

It should be noted that in the nearly five years since this post, a version of OCaml is now probably about as mainstream as a language can get. F# is a fully supported .NET language.


Must resist snide comment.... must resist...
Was This Post Helpful? 0
  • +
  • -

#8 macosxnerd101  Icon User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 11334
  • View blog
  • Posts: 42,745
  • Joined: 27-December 08

Re: Week 42- OCaml

Posted 27 July 2015 - 08:35 AM

Resistance is futile.

Posted Image
Was This Post Helpful? 0
  • +
  • -

#9 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 6292
  • View blog
  • Posts: 13,456
  • Joined: 16-October 07

Re: Week 42- OCaml

Posted 27 July 2015 - 08:48 AM

View Postjon.kiparsky, on 27 July 2015 - 11:33 AM, said:

Must resist snide comment.... must resist...


Why start now? :P
Was This Post Helpful? 0
  • +
  • -

#10 g4143  Icon User is offline

  • New D.I.C Head

Reputation: 15
  • View blog
  • Posts: 46
  • Joined: 30-April 09

Re: Week 42- OCaml

Posted 27 July 2015 - 08:51 AM

View Postbaavgai, on 27 July 2015 - 06:00 AM, said:

Dude! You're necroing all the weeks of code? :P/>

It should be noted that in the nearly five years since this post, a version of OCaml is now probably about as mainstream as a language can get. F# is a fully supported .NET language.


I'll surrender to a point which states that many, many functional concepts and ideas developed in functional languages are mainstream today but I don't see any functional language as being mainstream today. I see modern 'popular' functional languages presented as elaborate language extensions with Scala and F# being good examples of that point.
Was This Post Helpful? 1
  • +
  • -

#11 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 6292
  • View blog
  • Posts: 13,456
  • Joined: 16-October 07

Re: Week 42- OCaml

Posted 27 July 2015 - 09:10 AM

View Postg4143, on 27 July 2015 - 11:51 AM, said:

I'll surrender to a point which states that many, many functional concepts and ideas developed in functional languages are mainstream today but I don't see any functional language as being mainstream today. I see modern 'popular' functional languages presented as elaborate language extensions with Scala and F# being good examples of that point.


I would tend to agree with this. The imperative have pillaged the declarative for their wealth at no loss to themselves, other than added complexity.

Both Scala and F# can be used in completely functional or non functional ways. I use F# on a daily basis. There are a few ways to make F# mutable and have never really felt compelled to use them. You only step out of functional programming when you need to deal with IO objects. Which, strangely, you have to do in the most totalitarian of functional languages, Haskell. Only, Haskell is far less friendly about it.

Damn, now that this thread is live, I think I have to do something in OCaml...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1