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

Understanding the functions elem and isInfixOf

Your problem is with the (** a) syntactic sugar. The thing is that (elem b) is just the partial application of elem, that is: However when we use back ticks to make elem infix, we get a special syntax for infix operators which works like this: So therefore, while So in the latter case your arguments are in the … Read more