Questions tagged [haskell-prelude]

Prelude is the standard Haskell module that is imported by default into all Haskell modules.

Prelude is the standard Haskell module that is imported by default into all Haskell modules unless either there is an explicit import statement for it, or the NoImplicitPrelude extension is enabled.

See full documentation here: http://hackage.haskell.org/package/base-4.10.1.0/docs/Prelude.html

46 questions
15
votes
2 answers

Haskell Prelude with hiding, how to undo?

In one file I need to use the regular prelude (++) operator and I also wish to implement my own behaviour for (++). I have used import Prelude hiding (++) at the top of my file, defined my own (++) operator and now further below I wish to refer to…
user997112
  • 29,025
  • 43
  • 182
  • 361
10
votes
1 answer

Haskell's read function explanation

I wonder if someone is familiar with the Prelude´s read function in Haskell. The type of this function is following. Read a => String -> a Can someone explain me with a few examples how this function can be used and into what types the String can…
sergeantSalty
  • 179
  • 1
  • 1
  • 10
9
votes
1 answer

The missing folds

If you want to fold a list, I see four ways to do it. Fold from the right of the list, with the recursive term on the right foldrr (-) 100 [1..10] = 1 - (2 - (3 - (4 - (5 - (6 - (7 - (8 - (9 - (10 - (100)))))))))) = 95 foldrr :: (a -> b -> b) ->…
martin
  • 1,102
  • 2
  • 12
  • 20
9
votes
3 answers

What actually $ function does in haskell?

I know $ :: (a->b) -> a -> b f $ x = f x Intuitively it seems to me, like to say, 1. $ delays the evaluation of the function to its left 2. evaluates whats to its right 3. feeds the result of its left to its right. And it makes perfect sense…
Znatz
  • 1,530
  • 2
  • 18
  • 31
7
votes
4 answers

Prelude exponentiation is hard to understand

I was reading the Haskell Prelude and finding it pretty understandable, then I stumbled upon the exponention definition: (^)              :: (Num a, Integral b) => a -> b -> a x ^ 0            =  1 x ^ n | n > 0    =  f x (n-1) x …
Caridorc
  • 6,222
  • 2
  • 31
  • 46
7
votes
1 answer

Is there a way to view a list of Prelude functions from the Haskell console?

Is there a way to view a list of Prelude functions (such as Data.Char) from the Haskell console, instead of visiting Hoogle?
6
votes
2 answers

Is there a function in Prelude to pair a value with that value applied to a function?

I am searching for a function which looks something similar to this: withSelf :: (a -> b) -> a -> (a, b) withSelf f x = (x, f x) I have searched with Hoogle for such a function; I searched for (a -> b) -> a -> (a, b) and a -> (a -> b) -> (a, b),…
Tom Galvin
  • 861
  • 7
  • 12
5
votes
1 answer

Is there Liquid Haskell enabled Prelude?

Is there a annotated variant or Haskell Prelude available for easy migration of existing programs that call functions like head or length?
sevo
  • 4,559
  • 1
  • 15
  • 31
4
votes
2 answers

Definitions that are implicitly imported to GHCi, even with -XNoImplicitPrelude

When a GHCi session loads a file with {-# LANGUAGE NoImplicitPrelude #-} directive, it will unload most of the Prelude definitions: GHCi, version 8.10.6: https://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /path/to/.ghci [1 of…
4
votes
3 answers

What is the way to describe the type signature of Haskell functions that are not type-specific?

Given a function like negate, it has the type signature: negate :: Num a => a -> a which I would describe as a being the type in the context of Num (correct me if you think I am wrong). But I not fully sure how to describe something like last,…
Jake Jackson
  • 1,055
  • 1
  • 12
  • 34
4
votes
3 answers

How to define a lambda function that filters list based on subtype of a sum type?

The example is taken from a "Haskell programming from first principles" The goal of filter function is get rid of all the objects except those of 'DbDate' type. On somone's github I found a way to filter sum types with list comprehension and pattern…
3
votes
1 answer

Hide GHC base library to prevent pattern matching desugaring to GHC.Num.fromInteger use

I have created a replacement Prelude for use in teaching beginning Haskell students, called FirstPrelude. One of the aims is to expunge type classes from the standard library so that error messages are more of the classic Hindley-Milner variety,…
dorchard
  • 1,198
  • 8
  • 15
3
votes
2 answers

How can I find the definition of a Prelude function?

I'm currently trying to find the definition of the words function to help get an idea for a similar function I'm writing. So I was wondering is there somewhere that has all the definitions of the Prelude functions? Maybe a GHCi command to show the…
3
votes
2 answers

Detect what function is raising the exception Prelude.!!: negative index

I could not figure out in my code what function is raising (*** Exception: Prelude.!!: negative index since this exception is not very descriptive about the error. Is there any way to detect exactly what custom function is calling !! and raising…
svex99
  • 518
  • 4
  • 10
3
votes
1 answer

Haskell map function for two lists

I need to apply a function to two lists. The map function is map :: (a->b) -> [a] -> [b], however I need something more like map2 :: (a->b->c) -> [a] -> [b] -> [c]. Is there a prelude function similar to map that can do this?
1
2 3 4