toad.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
Mastodon server operated by David Troy, a tech pioneer and investigative journalist addressing threats to democracy. Thoughtful participation and discussion welcome.

Administered by:

Server stats:

310
active users

#haskell

11 posts10 participants1 post today
Replied to das-g

@das_g True. It is certainly magical that there is a programming language which defines a state monad called “IO” (or sometimes “Effect”) which carries around with it a symbol of the entire Real World in order to model the idea that any evaluation of a function of that type of monad may (or may not) create a change somewhere out in the real world, as opposed to “pure” functions which can only ever manipulate the stack.

Replied to Profoundly Nerdy

@profoundlynerdy just because something has types doesn’t make it Haskell-like. Haskell’s type system is in the family of Lambda Calculii (the “Lambda Cube”) which is called “System-F”.

I don’t know much about Raku, but it seems to me to me to be a bit more similar to TypeScript. And what differentiates TypeScript from other languages: it takes a horrible programming language like JavaScript and makes it less bad by giving it a type system, likewise Raku makes Perl less bad in the exact same way. (Sorry, I’m not trying to be impolite, but JavaScript and Perl are objectively, truly awful, horrible programming languages.)

So I see both Raku and TypeScript only being useful to a company buried in the technical debt of a hugely profitable production application that was very unwisely written in a dynamically typed language (Perl or JavaScript), which then unfortunately grew to millions of lines of code, and now it can’t be maintained by anyone, and it could never possibly be rewritten from the ground-up in a good programming language like Haskell for any reasonable sum of money. So Raku and TypeScript both offer a half-measure solution to that problem: make the maintenance of horrible computer code a bit easier with a type system.

Haskell was never intended as a fix for horrible code, it took a really good experimental programming language called Miranda and turned it into something that you can use to do real, practical software engineering, and it does it better than any other language ever invented. You write a system in Haskell because you know up front that you want it to be stable and maintained in a cost-effective manner for decades.

Zig is not similar to Raku or Haskell. It is more analogous to what Scala does for Java. Java is already statically typed, but Scala’s type system is better, and it’s runtime is fully compatible with Java. Likewise, Zig is fully compatible with the C language runtime, but provides a slightly different, slightly better static type checking system than the C type system. Zig also solves a bunch of other problems that C has by providing it with modern features like namespaces and modules, which makes it much easier to use than C. Zig is the perfect way to replace old C code with something more modern, but only if you don’t need it to be as rigorously correct as Rust. I think Zig would be a nice language to use to replace non-safety-critical front-end libraries like Gtk, or maybe for things like game engines.

Why is #Rakulang seemingly so underappreciated?

#Ziglang and #Haskell seem to outpace Raku's adoption curve. I say that as a fan of all three languages, I'm not casting shade. One is new and the other is niche, but they both seem to me good comparisons to Raku. Just look at the sizes of each language's subreddit to get a sense of respective community size.

If those are bad comparisons, I'm open to alternatives and polite discussion.

Is it just me, or is this a weird post by Sandy Maguire?

The Maybe formulation is incorrect -

`unionWith :: (Maybe a -> Maybe b -> c) -> Map k a -> Map k b -> Map k c`

And that the version with `These` is the right one to use -

`unionWith :: (These a b -> c) -> Map k a -> Map k b -> Map k c`

But then Sandy immediately discards this formulation, and instead builds up a monoidal strawman, which is equivalent to the Maybe formulation, to knock down. To get some law that doesn't hold anyway?

https://reasonablypolymorphic.com/blog/api-analysis/

#Haskell

reasonablypolymorphic.comAnalyzing API Design via Algebraic Laws :: Reasonably Polymorphic

I've just done a couple of #haskell exercises where the solution needed the following compositions

(pure . pure)

(fmap . fmap)

(liftA2 . liftA2)

Apart from the first one, my brain finds it difficult to establish an intuitive understanding of them.

I can't say "oh of course I know what it does"

My question is - do most haskell / functional programmers find this difficult or is it just me?

#haskell question

im enjoying this exercise !

I'm asked to write my own version of the Applicative <*> operator using liftA2 and pure.

The exercise defines <#>, myLiftA2 and myPure for a MyApplicative.

---

my solution passes the mooc tests

(<#>) :: MyApplicative f => f (a -> b) -> f a -> f b
g <#> x = myLiftA2 id g x

---

question - my solution doesn't use a pure / myPure ... does that mean `id` should not be allowed?

Just spent a good half hour pulling my hair out trying to figure out why one of the #elisp functions I had just written was always returning nil when I tested it. Turns out, my test was mistakenly passing its inputs to the wrong (but similarly named) function (pivot-table-get-columns instead of pivot-table-get-body).

#Haskell's type system would've caught this. 🙃

#haskell help needed - been struggling with this one for 2 days!

---

data Arg = Number Int | Variable Char
deriving (Show, Eq)

data Expression = Plus Arg Arg | Minus Arg Arg
deriving (Show, Eq)

parseExpression :: String -> Validation Expression
parseExpression s = validatedLength *> validatedExpression

where
[a, op, b] = words s
--
validatedLength = check (length (words s) == 3) ("Invalid expression: " ++ s) ()

---

1/2

I'm feeling really stupid re #haskell

my solution to the exercise passes the mooc tests but it is really ugly

is there a more elegant idiomatic way to do this?

in essence I'm finding it hard to 'pass values" through different contexts like Maybe, Either, Validation

(code is also alt text in image)

#haskell question

Trying to make the following work:

--

calculator :: String -> String -> Maybe Int

calculator op num = (readMaybe op::????) <*> (readMaybe num::Int)

---

I'm not sure how I can get

readMaybe op::???

to convert the string `op` into `Just myfunction`

I have to give readMaybe a type so tried abstract data types - it failed

double = (2 *)
data Command = Command negate | Command double
deriving (Read)

calculator op num = (readMaybe op::Command) <*> (readMaybe num::Int)

#haskell help requested

I'm learning about Applicative operators like liftA2 and <$> and <*>

---

my solution to an exercise works but I think I'm missing a better way that uses liftA2

statements :: [String] -> [String] -> [String]
statements xs ys = myfn <$> [1,2] <*> xs <*> ys
where
myfn 1 x y = x ++ " is " ++ y
myfn 2 x y = x ++ " is not " ++ y

(the aim is to generate all combinations is / is not)

---

I wanted to do something like

liftA2 [f1, f2] xs ys

but that doesn't work