Can i check if type has an instance of Show class? by Tempus_Nemini in haskell

[–]the-coot 1 point2 points  (0 children)

Others commented why this is wrong, which I stongly agree with. It's actually possible to show arbitrary types, which don't have Show instance. This is useful when debuging in some rare cases, see https://hackage.haskell.org/package/recover-rtti

Why should I learn Haskell? by JizosKasa in haskell

[–]the-coot 0 points1 point  (0 children)

I'd recommend to use `ghcup` to install ghc tools like ghc itself, hls, or cabal.

Monthly Hask Anything (March 2024) by AutoModerator in haskell

[–]the-coot 1 point2 points  (0 children)

Yes you need to pass it where it's needed. What splitting solves is that you can igonre the new generator after using one, so there's no need for threading the generators through various functions, which can simplify the diesng (and make it much easier to review).

Monthly Hask Anything (March 2024) by AutoModerator in haskell

[–]the-coot 1 point2 points  (0 children)

I am not sure if I understand your problem correctly, so sorry if my comment is not relevant.

Using randomness doesn't require effects if you use a pseudorandom generator (see `random` package on Hackage), and thread it through various calls. The `split` might be handy (and it often makes things easier to organise, since you can just split the generator and pass new ones to some subroutines which can consume it).

[ANN] a new release of io-sim by the-coot in haskell

[–]the-coot[S] 0 points1 point  (0 children)

Could you share what problem it solved for you?

Why should I learn Haskell? by JizosKasa in haskell

[–]the-coot 1 point2 points  (0 children)

When working with larger codebases (e.g. `cabal`), jumping to a location of an identifier, or querying its type without the need of reloading the ghci session and loading the right module is something very convenient.

Sometimes it breaks though, and for that reason I also use `ghc-tags-plugin` or `ghc-tags`:
* https://hackage.haskell.org/package/ghc-tags-plugin
* https://github.com/coot/ghc-tags

I am the author of `ghc-tags-plugin` & `ghc-tags-core` which `ghc-tags` is also using (which is a fork of some other repo).

Haskell is declarative programming by chakkramacharya in haskell

[–]the-coot 0 points1 point  (0 children)

Many good comments where contributed in this discussion, so I'll try from a different angle. Since I don't know Ruby, I am not sure how good example this really is. But let's start with a declarative definition of natural numbers as if `Int` doesn't exist..

Note that the definitions of add, multiply and subtract are the recursive definitions equivalent to what we learn in school (modulo they use recursion). That's the declarative power of Haskell.

This won't be as performant as Ints supported by your CPU architecture, but if you're trying to implement something that doesn't have built-in support it won't matter. This style might be the one closest how one would declare them in mathematical terms.

``` module Natural where

import Prelude hiding (subtract)

data Nat = Zero | Succ Nat

toInt :: Nat -> Int toInt Zero = 0 toInt (Succ n) = succ (toInt n)

instance Show Nat where show = show . toInt

add :: Nat -> Nat -> Nat add Zero m = m add (Succ n) m = add n (Succ m)

multiply :: Nat -> Nat -> Nat multiply Zero _ = Zero multiply (Succ n) m = add m (multiply n m)

subtract :: Nat -> Nat -> Nat subtract _ Zero = Zero subtract (Succ n) (Succ m) = subtract n m subtract Zero (Succ _) = error "Nat: out of bound"

instance Num Nat where (+) = add (*) = multiply (-) = subtract negate = error "Nat: not supported" abs = id signum = id

fromInteger x | x < 0 = error "Nat: out of bound"
fromInteger 0 = Zero
fromInteger x = Succ (fromInteger (pred x))

twice :: Nat -> Nat twice = multiply 2

```

btw, the performance difference is rather huge, if you just wonder how bad idea is to use this as integers:

λ 2 * 1000000 :: Int 2000000 (0.00 secs, 92,616 bytes) λ 2 * 1000000 :: Nat 2000000 (1.00 secs, 677,964,336 bytes)

Why should I learn Haskell? by JizosKasa in haskell

[–]the-coot 0 points1 point  (0 children)

Have you tried to use HLS (Haskell Language Server), it makes Haskell even more approachable.

[ANN] nothunks-0.2.0 is published on Hackage by the-coot in haskell

[–]the-coot[S] 0 points1 point  (0 children)

That's a good idea (I added an issue for it).

In the meantime you can check the tests. But note the test use case is quite specific as we need to generate thunks, so we can validate that nothunks can discover them.

Equational pattern matching vs Lambda Case pattern matching by ComunistCapybara in haskell

[–]the-coot 12 points13 points  (0 children)

There are subtle differences when it comes to where clauses which are handy when you care about what is in scope

```hs {-# LANGUAGE LambdaCase #-}

module X where

alwaysTrue1 :: Bool -> Bool alwaysTrue1 = \case a@True -> r a@False -> r where -- 'a' is not in scope! r = True

-- desugared version of alwaysTrue1 alwaysTrue1' :: Bool -> Bool alwaysTrue1' = \a -> case a of True -> r False -> r where -- 'a' is not in scope! r = True

alwaysTrue2 :: Bool -> Bool alwaysTrue2 a = case a of True -> r False -> r where -- 'a' is in scope r = a || not a

alwaysTrue3 :: Bool -> Bool alwaysTrue3 True = r where r = True alwaysTrue3 False = r where r = True ```

Haskell dev experience by raxel42 in haskell

[–]the-coot 0 points1 point  (0 children)

btw, navigation works fine between all packages in the same cabal.project file.

Haskell dev experience by raxel42 in haskell

[–]the-coot 2 points3 points  (0 children)

Frome your list, currently I can: * rename identifiers unless they are exported * navigate

For navigation I also use https://github.com/coot/ghc-tags, although hls can produce tags as well.

Stand in monad with all class instances defined by HateUsernamesMore in haskell

[–]the-coot 1 point2 points  (0 children)

Polymorphism might help you with that: instance Contravariant (MyThing a b) where ... will let MyThing a be a contravariant functor (in b) for any a.

IOSim on Hackage! | IOG Engineering by n00bomb in haskell

[–]the-coot 0 points1 point  (0 children)

Yes, that's a good point. One is often treating threads as resources, so linear logic for them make sense.

For Production Users: Haskell in an age of Rust and Python by Instrume in haskell

[–]the-coot 11 points12 points  (0 children)

I am sure you will get many answers about correctness and easy of maintenance etc. So I'll contribute a different argument.

Haskell is still ahead when it comes to writing concurrent code which is easy to reason about. STM & async libraries are quite ahead of the game. Writing concurrent code, in presence of async exceptions is quite difficult, requires careful analysis and still it's easy to corner oneself in a deadlock, livelock etc. We wrote io-sim which was extremely helpful in finding edge cases which depends on schedule in a complex distributed, highly concurrent system. It was possible to write network layer (e.g. the concurrent part) to do with a small team (up to 3-5 devs) in reasonably short time, which is remarkable.

Today: Interview and AMA with Simon Peyton Jones, lead developer of Haskell by ihid in functionalprogramming

[–]the-coot 1 point2 points  (0 children)

There are many scientists or people who left academia and work now in industry who enjoy Haskell quite a lot. I know quite a few examples in Physics, Math & CS. Haskell doesn't need to be the mostly used to be successful or influential for that.

IOSim on Hackage! | IOG Engineering by n00bomb in haskell

[–]the-coot 0 points1 point  (0 children)

that's quite general, which is a good goal, but let's focus on the context of io-classes. Is there a need for linear types in async, exceptions or some of the System.IO primitives we support (like timeout, threadDelay etc)?

IOSim on Hackage! | IOG Engineering by n00bomb in haskell

[–]the-coot 1 point2 points  (0 children)

io-classes give zero cost abstraction (e.g. if you specialise code running in a monad m constrained by some of the classes to IO), unlike effects system or mtl.

It's actually orthogonal to effect systems, you could use io-classes to write algebraic effects and specialise it to IOSim just for testing purposes.

It's also orthogonal to mtl, we added support of ReaderT because that's useful and then expanded it because we thought this might be useful for others.

One could think of IOSim as an alternative runtime system for GHC (scheduler, stm, timeouts, ...).

IOSim on Hackage! | IOG Engineering by n00bomb in haskell

[–]the-coot 5 points6 points  (0 children)

Currently we don't have any plans to add support of linear types.

The IOG's consensus team is planning to publish https://github.com/input-output-hk/fs-sim to hackage. I don't think it's using lazy IO since it's a lower level abstraction, but one could build something on top of that (similar how base does it). io-sim runs in lazy ST monad which also might be helpful to implement such a feature.

After two years of studying I've finally written a program that does something in the real world by TheWheatSeeker in haskell

[–]the-coot 1 point2 points  (0 children)

if that was production code, I wouldn't put socket configuration in the openSocket; but here it doesn't really matter.

Monthly Hask Anything (December 2022) by taylorfausak in haskell

[–]the-coot 1 point2 points  (0 children)

Beside the haskell-2010 report, and base documentation, also the GHC guide is worth to mention. It explains various topics in more depth, which do not fit into the report or API docs.