Need help writing simple Haskell program please

In summary, Haskell is a functional programming language with a strong type system and the ability to handle complex data structures. It offers benefits such as better code readability and built-in support for concurrency and parallelism. To get started writing a simple Haskell program, you need to download a compiler, familiarize yourself with the syntax and basic concepts, and start writing and testing your code. Some common errors and challenges include type and syntax errors, as well as understanding advanced concepts like monads and lazy evaluation. However, there are many online resources and communities available to help, such as tutorials, forums, and meetups.
  • #1
chuy52506
77
0
So for my program I want to input this line of code:

addPairs 10 [(2,3),(4,15),(87,92),(23,45)]

Where the 10 after addPairs is the minimum distance the pair (x,y) must have in order to be outputted as [x+y]
For example :
addPairs 10 [(2,3),(4,15),(87,92),(23,45)]

would output:
[ 19, 68 ]

SO far this is what I have:

diffTuple :: (Int,Int) -> Int
diffTuple (x,y) = abs (x-y)

addDistantPairs :: addDistantPairs :: Int -> [(Int,Int)] -> [ Int ]
addDistantPairs n [(x,y)]
| diffTuple(x,y)>= n = addPairs[(x,y)]
| otherwise = [0]
 
Technology news on Phys.org
  • #2
anyone??
 

1. What is Haskell?

Haskell is a functional programming language that is used for writing high-level, declarative programs. It is known for its strong type system and its ability to handle complex data structures.

2. Why should I use Haskell for my program?

Haskell offers many benefits, such as better code readability, easier debugging, and built-in support for concurrency and parallelism. It also has a strong community and a large library of useful functions and tools.

3. How do I get started writing a simple Haskell program?

The first step is to download and install a Haskell compiler, such as GHC. Then, familiarize yourself with the syntax and basic concepts of the language, such as functions, types, and pattern matching. Finally, start writing and testing your program in a text editor or an integrated development environment (IDE).

4. What are some common errors or challenges when writing a Haskell program?

Some common errors in Haskell include type errors, syntax errors, and infinite recursion. It can also be challenging for beginners to understand and use advanced concepts like monads and lazy evaluation. However, with practice and learning resources, these challenges can be overcome.

5. Are there any resources or communities that can help me with writing my Haskell program?

Yes, there are many online resources and communities for Haskell, such as tutorials, forums, and open-source projects. Some popular resources include the official Haskell website, Haskell Wiki, and the Haskell subreddit. You can also join a local Haskell meetup group or attend conferences and workshops to learn from other Haskell developers.

Similar threads

  • Programming and Computer Science
Replies
1
Views
754
  • Programming and Computer Science
Replies
25
Views
2K
  • Programming and Computer Science
Replies
6
Views
898
  • Programming and Computer Science
Replies
4
Views
623
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
2
Replies
53
Views
3K
Replies
10
Views
961
  • Programming and Computer Science
2
Replies
55
Views
4K
  • Programming and Computer Science
Replies
20
Views
1K
  • Programming and Computer Science
Replies
32
Views
2K
Back
Top