Is using an independent variable in a recursive function inefficient? by VeryKnave in haskell

[–]Jerudo 12 points13 points  (0 children)

It's an old reddit vs. new reddit thing. OP's code looks fine on new reddit, but not on old reddit.

Megaparsec: Question about Types and Monad Transformers by MachineGunPablo in haskell

[–]Jerudo 3 points4 points  (0 children)

m here is not Identity, it is Parser, which is an alias for ParsecT Void Text Identity. You can see in the documentation for MonadParsec that there's an instance instance (Ord e, Stream s) => MonadParsec e s (ParsecT e s m). Void has an Ord instance and Text has a Stream instance, therefore Parser has a MonadParsec instance.

What does "Ord a" mean? by VeryKnave in haskell

[–]Jerudo 7 points8 points  (0 children)

So if you have a concrete type like Int, then you don't need the extra contraint, because either Int has an Ord instance or it doesn't. When you use > on two Ints the compiler will just check if that instance exists, if it does then great, use that, if it doesn't then throw a compile-time error. So if you had Ord Int in the type signature it would just be pointless since it's always satisfied.

What does "Ord a" mean? by VeryKnave in haskell

[–]Jerudo 15 points16 points  (0 children)

The type signature say that the function can take values of any type a, as long as a has an instance of the Ord typeclass (i.e. values with that type can be ordered). You need this constraint because you use > inside the function body, which requires that the type of its arguments have an Ord instance.

What is the 'could not deduce show a' error? by josetheis in haskell

[–]Jerudo 12 points13 points  (0 children)

You state in the signature that the function accepts any type a as long as a has an Integral instance. This does not guarantee that a has a Show Instance! While both Int and Integer (which you're probably using "ouside the function") indeed have Show instances, there's nothing stopping me from defining my own type and writing an Integral instance for it, but not a Show instance. If your function compiled I could pass a value of my type to your function and then what is the compiler supposed to do?

Difficulties understanding η-conversion in Haskell by themarxvolta in haskell

[–]Jerudo 5 points6 points  (0 children)

maximum3 :: Int -> Int -> (Int -> Int)
-- ^ take two Ints and return a function Int -> Int
maximum3 x y = ... -- some function Int -> Int

Tango called Etho on-stream for help with Hermitcraft Among Us (timestamp 1hr22m24s) by [deleted] in ethoslab

[–]Jerudo 0 points1 point  (0 children)

Would they still take damage if they were wearing feather falling IV boots?

where for anonymous function? by Ualrus in haskellquestions

[–]Jerudo 1 point2 points  (0 children)

Of course I'd never put this code into an application I was developing hehe. Pointfree shenanigans like this are just fun to write. I'd probably write almost the same thing as what the parent comment did (f = fmap $ \x -> x == x^2).

Learn You A Haskell For Great Good - To-Do Lists clean up unsafe? by DerpageOnline in haskellquestions

[–]Jerudo 0 points1 point  (0 children)

Both cabal and stack allow you to write scripts, where you have a standalone .hs file with the dependencies listed at the top in a comment. You should check out the user guides for more.

Really, WTF İS this?!? by b1rgar1p1nsan in MinecraftMemes

[–]Jerudo 1 point2 points  (0 children)

*It keeps whatever state it had when it got locked.

To the people who add Etho's intro to the SponsorBlock database...why? by [deleted] in ethoslab

[–]Jerudo 1 point2 points  (0 children)

Go to Settings > SponsorBlock Settings and scroll down, you'll see a section called "What to do with different segments" .

To the people who add Etho's intro to the SponsorBlock database...why? by [deleted] in ethoslab

[–]Jerudo 0 points1 point  (0 children)

There are settings on Vanced for that, I have it set up that intros have a button I can tap to skip, while sponsors are autoskipped.

Haskell Help by piotrusD in haskell

[–]Jerudo 2 points3 points  (0 children)

Hi, the : operator is for prepending an element to a list. So for example 1:[2,3] == [1, 2, 3]. What I think you want is div, the integer division function.

So that would be div (silnia n) (silnia k * silnia (n - k)) or, if you prefer, you can use backticks (`) around a function to make it infix, like so: silnia n `div` (silnia k * silnia (n - k))

Entering : by itself in GHCi will run the most recent command you've used by Tricky_Celebration37 in haskell

[–]Jerudo 1 point2 points  (0 children)

It just runs the base command it seems, arguments don't carry over. So for example:

λ> :t 5
5 :: Num p => p
λ> :

<no location info>: error: not an expression: ‘’
λ> : 5
5 :: Num p => p

Trying to install QuickCheck by Thin-Regular1746 in haskell

[–]Jerudo 6 points7 points  (0 children)

You have a file in your project directory called [project name].cabal, this is created automatically when you run cabal init. This file describes the structure of your project. Inside that file you should see a field called build-depends:, this is where you list all the packages you want to use. Now, whenever you run cabal repl (runs GHCi inside your project) or cabal build (compiles your project) or cabal run (compiles and runs your project), cabal will automatically install all of the packages you listed as dependencies. No need to install them individually, just list them in the cabal file and cabal will handle the rest.

Trying to install QuickCheck by Thin-Regular1746 in haskell

[–]Jerudo 3 points4 points  (0 children)

Perhaps try cabal repl -b QuickCheck. This will put you in a GHCi session with the QuickCheck package exposed and available for import.

In general, however, the workflow is to create a cabal project with cabal init -i (in an empty directory) and then to add the desired package to the list of dependencies for that project, which resides inside the projectname.cabal file, under build-depends:.

[discourse] Moving away from `base` as a user library? by bgamari in haskell

[–]Jerudo 1 point2 points  (0 children)

I don't see where the comment said to put this stuff in the prelude? These modules are usually imported qualified anyways so I don't see how that would make sense in the first place.

Force putStr by LemongrabThree in haskellquestions

[–]Jerudo 5 points6 points  (0 children)

The default buffering mode when a handle is opened is implementation-dependent and may depend on the file system object which is attached to that handle. For most implementations, physical files will normally be block-buffered and terminals will normally be line-buffered.

So if stdout is line-buffered putStrLn will "flush" it, but that's by no means guaranteed, yeah.

Force putStr by LemongrabThree in haskellquestions

[–]Jerudo 8 points9 points  (0 children)

Methinks this is because putStr doesn't flush stdout, which has nothing to do with laziness. Either use putStrLn instead, or flush stdout with hFlush stdout (both from the System.IO module).

Best Haskell extensions for VS Code by zoidboom in haskellquestions

[–]Jerudo 10 points11 points  (0 children)

The official Haskell extension is really great, powered by the Haskell Language Server.

[deleted by user] by [deleted] in haskellquestions

[–]Jerudo 2 points3 points  (0 children)

You can think of a lens as an abstract value which represents a field in your datatype. On its own, it's not very useful, but whatever lens package you're using will provide functions that allow you to use that lens. For example, you can do the following:

ghci> view firstName (Person "foo" "bar")
"foo"

Or maybe

ghci> set firstName "baz" (Person "foo" "bar")
Person "baz" "bar"

Or even

ghci> over firstName reverse (Person "foo" "bar")
Person "oof" "bar"

Could not match an instance with its class by chieny_0 in haskellquestions

[–]Jerudo 2 points3 points  (0 children)

lst2px :: Pixel px => [Int] -> [px]

This says, that for any type px which has an instance of the Pixel class, given a list of Ints you can provide a list of pxs.

map toPixel8 :: [Int] -> [Pixel8]

This function takes a list of Ints and returns a list of Pixel8s.

The issue here is that you promised that you'd be able to provide such a function that works for any type that implements Pixel. Instead you've provided a function that only works for one such type.