What does the “Just” syntax mean in Haskell?

It’s actually just a normal data constructor that happens to be defined in the Prelude, which is the standard library that is imported automatically into every module. What Maybe is, Structurally The definition looks something like this: That declaration defines a type, Maybe a, which is parameterized by a type variable a, which just means that you can … Read more

Division in Haskell

Use div, which performs integer division: The (/) function requires arguments whose type is in the class Fractional, and performs standard division. The div function requires arguments whose type is in the class Integral, and performs integer division. More precisely, div and mod round toward negative infinity. Their cousins, quot and rem, behave like integer division in C and round toward zero. div and mod are usually correct when doing modular arithmetic (e.g. … Read more

How to fix “variable not in scope” error in GHCI?

I see you are defining your function in interactive shell. Most of Haskell’s REPLs read and eval instructions line-by-line, so when you type potencia :: Integer -> Integer -> Integer it is interpreted right at this moment, so compiler complains that potencia is lacking implementation. You should either: Define it in external file and load it using :l (recommended) Type :set … Read more

Haskell Merge Sort

This is an implementation of Mergesort using higher order functions,guards,where and recursion. However getting an error from compiler 6:26: parse error on input ‘=’ I can’t see whats wrong? or rather I don’t understand the compiler.

Reverse a list in haskell

You are separating the list into head and tail, but then re-assemble the list in the same order. Take the list [1, 2, 3] for example: In the first call, x will be 1, and xs will be [2, 3]. Then you create a new list, consisting of x (so 1) at the front, followed … Read more

How do I use the filter function in Haskell?

You got it, pretty much. So the rest of the deal is designing the predicate function for your list. Assuming you already had a list called xs and a predicate function p, all you’d have to do is Often, you’ll see p defined as an anonymous, or lambda, expression, like so: It is not necessary, … Read more