Questions tagged [classy-prelude]

An alternative Haskell prelude based on Typeclasses

classy-prelude is an alternative Haskell prelude based on typeclasses.

It is a rather radical approach on alternative preludes and intended for experienced Haskellers trying to increase productivity.

See So many Preludes!, ClassyPrelude: The good, the bad, and the ugly, The classy prelude and Clarification: classy prelude for further information from the author Michael Snoyman.

12 questions
13
votes
1 answer

How to understand `MonadUnliftIO`'s requirement of "no stateful monads"?

I've looked over https://www.fpcomplete.com/blog/2017/06/tale-of-two-brackets, though skimming some parts, and I still don't quite understand the core issue "StateT is bad, IO is OK", other than vaguely getting the sense that Haskell allows one to…
bbarker
  • 11,636
  • 9
  • 38
  • 62
9
votes
1 answer

Classy-Prelude (head . head)

I'm trying to convert several projects to classy-prelude at the moment. While most behaviour seems quite straightforward to me, the (head . head) gives mysterious errors on a simple 2D list. Consider the following GHCi session: Prelude> (head .…
Uli Köhler
  • 13,012
  • 16
  • 70
  • 120
7
votes
2 answers

Is there anything we lose with MonoFoldable?

MonoFoldable in the mono-traversable package seems to be able to implement all of the usual Foldable containers and more, for example, things like Bytestring and homogeneous tuples can be made MonoFoldable but not Foldable. My question is, do we…
Clinton
  • 22,361
  • 15
  • 67
  • 163
4
votes
3 answers

Is there a convenient way to construct larger type level Peano numbers using mono-traversable?

The mono-traversable package uses type level Peano numbers for MinLen. I can construct them using chained Succs: toMinLen [1,2,3] :: Maybe (MinLen (Succ (Succ Zero)) [Int]) but this quickly gets out of hand: toMinLen [1,2,3] :: Maybe (MinLen (Succ…
MaxGabriel
  • 7,617
  • 4
  • 35
  • 82
3
votes
1 answer

How to write a "retryForever" function in Haskell using exception handling?

I'd like to create a function that can recover from as many errors as is reasonable, and try again. Of course, meaningful handling of errors is covered in other parts of the program - this is a last ditch effort to keep things running. So I wrote…
bbarker
  • 11,636
  • 9
  • 38
  • 62
3
votes
0 answers

Newtype deriving IsSequence

I have a newtype X, which is basically a list of Ints. I use ClassyPrelude instead of the standard Prelude and want to derive the IsSequence class. This makes it necessary to also derive lots of other classes. The language extension…
1
vote
1 answer

How to log all exceptions in Haskell?

Original Title: How to deal with multiple instances of Exception types when inspecting all Exceptions? I have the following imports (note my prelude is actually ClassyPrelude, which uses UnliftIO.Exception). Note that System.Logger is from tinylog,…
bbarker
  • 11,636
  • 9
  • 38
  • 62
1
vote
1 answer

Is there any replacement for Prelude's iterate function in classy prelude?

In the standard prelude: Prelude> :t iterate iterate :: (a -> a) -> a -> [a] However, in classy prelude there is no iterate, so I presume there might be some more generic function to do the same, perhaps a monadic one. I just cannot figure out what…
Sami Liedes
  • 1,084
  • 8
  • 19
1
vote
2 answers

Cannot understand why MonoFoldable for my type doesn't compile, or the error message

I have the following code: {-# LANGUAGE NoImplicitPrelude, OverloadedStrings, TypeFamilies #-} module AI.Analysis.Rules where import ClassyPrelude -- Our set of rules data RuleSet a = RuleSet [Rule a] [Rule a] deriving (Eq) mkRuleSet :: (Ord…
Koz Ross
  • 3,040
  • 2
  • 24
  • 44
0
votes
1 answer

How to resolve: Couldn't match type ‘o’ with ‘Element mono0?

When pasting the following code from stm-conduit: mygatherFrom :: (MonadIO m, MonadUnliftIO m) => Int -- ^ Size of the queue to create -> (TBQueue o -> m ()) -- ^ Action that generates output values ->…
bbarker
  • 11,636
  • 9
  • 38
  • 62
0
votes
1 answer

Why does Element show up in a type error using Foldable (not MonoFoldable) in ClassyPrelude?

I have the following custom prelude: {-# LANGUAGE DataKinds #-} {-# LANGUAGE RankNTypes #-} module Prelude ( module ClassyPrelude , module Numeric.Units.Dimensional.Prelude , headMay , sec ) where import ClassyPrelude hiding ( (+), (-),…
bbarker
  • 11,636
  • 9
  • 38
  • 62
0
votes
1 answer

Yeson.json.object is applied to too many arguments

import Yesod import Data.Text data App = App instance Yesod App mkYesod "App" [parseRoutes| / Home GET |] getHome :: String -> Handler Value getHome = object ["name" .= ("Adam"::Text)] main = warpDebug 2012…
user2879704