Haskell equivalent of SML-like "return a function"

AI Thread Summary
In Haskell, to define a function that returns a function similar to the SML-like syntax, you can use lambda expressions. The example provided illustrates this with the function `foo`, which takes an argument and returns a function that increments its input by one. The concise version of this function can be expressed as `foo = const (+1)`. Additionally, there is a request for a Haskell function that removes consecutive duplicate characters from a string, such as transforming "abaacccdee" into "abacde". This requires implementing a function that processes the string and filters out adjacent duplicates.
Dragonfall
Messages
1,023
Reaction score
5
I want do the Haskell equivalent of SML-like "return a function"

fun foo x = fn x=>x+1

How do I do this in Haskell?
 
Technology news on Phys.org
Code:
foo :: a -> Int -> Int
foo x = \x -> x+1

This can be written more concisely as:

Code:
foo = const (+1)
 
Hi,People! I need to define in haskell a function which ignore all doublings . For example if i type a string "abaacccdee" in the end i get the string "abacde".
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
6
Views
2K
Replies
1
Views
2K
Replies
32
Views
2K
Replies
8
Views
1K
Replies
12
Views
2K
Replies
18
Views
1K
Back
Top