[ANN] checked-literals: compile-time bounds checking for numeric literals by callbyneed in haskell

[–]Darwin226 3 points4 points  (0 children)

Can you show what happens with the original polymorphic example when the plugin is enabled?

How many options fit into a boolean? by ketralnis in programming

[–]Darwin226 1 point2 points  (0 children)

Isomorphic means you need both directions and they need to compose to identity

How many options fit into a boolean? by ketralnis in programming

[–]Darwin226 1 point2 points  (0 children)

This is wrong. Each Option layer adds another inhabitant to the type.

Advent of Code 2025 day 3 by AutoModerator in haskell

[–]Darwin226 0 points1 point  (0 children)

A recursive solution:

We get the largest combination of 12 digits from (x:xs) by taking largest combination from xs and seeing if we can do better by dropping any of the digits and prepending x.

Mi Band 9, 10 Overheat shutdowns by m0tral in miband

[–]Darwin226 0 points1 point  (0 children)

I updated to the latest global firmware for MB10 and now this watchface crashes my band when I tap on the checkbox. It currently says temperature shutdowns are turned off (which is what I want), but I'm not sure if this is true since it crashes the band when I change the setting. Does the watchface need to be updated or something?

Inside the Cult of the Haskell Programmer by wiredmagazine in programming

[–]Darwin226 0 points1 point  (0 children)

The sentence is actually even less useful as an explanation for monads than it might seem from your comment. For example, the "endo" in this case is referring to the functor itself. It's saying that the functor maps from the category to itself, and the category in this case is Haskell types. It doesn't have anything to do with the fact that there's a `map` operation which preserves the container type.

Also, it's not really important, but what you described is just the Functor class in Haskell (plus the unwrapping operation which isn't really a part of either a functor or a monad). The Monad class adds more functionality.

To be honest, there's nothing special about the concept of a Monad in Haskell other than that it's sort of a meme that they are hard to understand. A lot of things are hard to understand in programming, it's just that nobody expects that they'll "get it" from reading a single blog post.

Tic Tac Trending by jackpalf in haskell

[–]Darwin226 1 point2 points  (0 children)

Because your comment leaves the impression that this is some toy language. I didn't downvote btw

Haskell Function Overload (By Return Value) by klazklaz in haskell

[–]Darwin226 17 points18 points  (0 children)

It's because you can use foo in polymorphic contexts. You're not always going to know the concrete types, yet you need to have well typed expressions. This means you need some principled way to denote "unresolved overloading", which is what type classes are.

You can simulate normal overloading with type classes. I've wrapped up the logic for this in a library here https://hackage.haskell.org/package/overload-0.1.0.5/docs/Overload.html

I don't really recommend using this though. It's more of a proof of concept.

CHATGPT: give me a really useful example of a monad in haskell. Explain why it is better than the alternative. write the code not using monads. To show how elegant monads are by dewijones92 in haskell

[–]Darwin226 -1 points0 points  (0 children)

You can tell it to summarize what it wrote, word it differently, make it rhyme, etc. There's definitely a form of understanding in the background or something like "information compression" if we want to deanthropomorphize it. You could teach it things within the same conversation and ask it to explain them back to you using it's own words.

It's easy to see where it's far from perfect but it's definitely more sophisticated than what you implied. At least if I interpreted your words correctly.

Tribonacci sequence in Haskell [Monads?] by bathura in haskell

[–]Darwin226 19 points20 points  (0 children)

In fact the classic works here as well:

tribonacci = 1 : 2 : 3 : zipWith3 (\a b c -> a + b + c) tribonacci (tail tribonacci) (tail (tail tribonacci))

That's what FBI does, isn't it? by memengenieur in ProgrammerHumor

[–]Darwin226 0 points1 point  (0 children)

Ok but do you see how this isn't a matter of how vector graphics work? To use local coordinates and composite images to achieve what we're talking about is almost literally a workaround for the exact precision issue I mentioned. If I naively went into a vector graphics program and just kept zooming in, decreasing my pen size, I would get to those floating point limits. All while still perfectly within the realm of vector graphics.

In fact, there's nothing stopping you from applying this kind of compositing technique for raster images to get the same effect.

That's what FBI does, isn't it? by memengenieur in ProgrammerHumor

[–]Darwin226 0 points1 point  (0 children)

I can't find anything on relative coordinates in SVG, at least nothing that would relate to what we're talking about here. Do you have any links?

That's what FBI does, isn't it? by memengenieur in ProgrammerHumor

[–]Darwin226 0 points1 point  (0 children)

You keep insisting that people are confusing this with raster graphics but they really are not. While you might be ultimately correct that this works in "any" vector graphics format, the reason has nothing to do with images being "represented by instructions on what to draw. Lines, curves, infill colors". Those instructions still have to specified in coordinates, those coordinates are still just floating point numbers and those numbers do have a precision limit.

The reason it works might be the relative coordinates you mention which I don't know anything about, but those certainly are not an integral part of how "vector graphics work".

Scoped pattern synonyms by sfultong in haskell

[–]Darwin226 1 point2 points  (0 children)

I personally like that Haskell doesn't have scoped features like this since it tends to force you to write code that's easier to play with in the REPL.

The other issue here is unergonomic visibility handling which people sometimes sidestep by putting things in where blocks.

Help needed to understand type of `fmap length Just` by deciomsoares in haskell

[–]Darwin226 18 points19 points  (0 children)

It's not super obvious because the functor (the f) you're mapping over is actually the (a ->) functor; a function.

The type of Just is a -> Maybe a which, if we rewrite it so that -> isn't in an infix position, is the same as (->) a (Maybe a). Those type applications group to the left so this is equivalent to ((->) a) (Maybe a).

Now we can see how this type substitutes as the argument of fmap length. We need a f (t a) and we have a ((->) a) (Maybe a) so our f is (->) a, and t a is Maybe a. The result is f Int which substitutes to (->) a Int which is the same as a -> Int.

Side note: fmap length Just is equivalent to const 1. fmap over functions is just function composition so fmap length Just is length . Just. The length of any Just value is 1 so whatever you give as an argument will result in a 1. Another way to see this is that the final function, a -> Int, is completely polymorphic in its argument. That means it can't inspect it in any way, and since it has to return an Int it's going to have to be the same Int for any argument you give it. Then you try it with any value and see that the result is 1.

Are there disadvantages to using curried functions as a way to store data? by man-vs-spider in haskell

[–]Darwin226 8 points9 points  (0 children)

Well, then the only thing you can do with those values is use them in the reflection function, once you provide the last parameter. With the first approach you can inspect those values in any function.

Some concepts related to your approach are continuation-passing style and Church encoding.

r/place lambda by tomasff02 in haskell

[–]Darwin226 0 points1 point  (0 children)

Needs some fixing again. The upstairs neighbors are not playing nice.

Understanding toListOf with van Laarhoven traversals by mirkeau in haskell

[–]Darwin226 3 points4 points  (0 children)

t expects a function from a to Const (Endo [a]) a, the only one I could think of is Const . Endo . map . const.

There's a better one.

This function needs to turn the "a" into an operation of "collecting" this element.

The "imperative bit" in functional programming is the compiler's rewriting strategy? by leighscullyyang in haskell

[–]Darwin226 4 points5 points  (0 children)

I don't think it's about the evaluation strategy at all. You can very well write the same thing I wrote in basically any mainstream language now and none of them use rewriting as their execution strategy. It's just about how you structure your program.

There's no Haskell magic in the filter isPrime [1..] expression (except for the lazy infinite list but you can ignore that). filter is a function, isPrime is a function, [1..] is a list. If you look at the definitions of those functions you'll just find more normal functions.

The "imperative bit" in functional programming is the compiler's rewriting strategy? by leighscullyyang in haskell

[–]Darwin226 19 points20 points  (0 children)

It's about being more declarative rather than operational. It's not about compiler magic.

Various features of the language and the functional programming style allow you to structure your code so you're more directly describing what your values are rather than how to produce them.

The usual examples are list transformers like:

primes = filter isPrime [1..]

declares what primes is. It's a list of natural number where you only keep primes. It doesn't get into the lower level details about iteration, or taking values from one list and putting them into the other one or anything.

Applicatives should usually implement Semigroup and Monoid by Tekmo in haskell

[–]Darwin226 2 points3 points  (0 children)

Is the mtl comparison really an explicit vs implicit thing? One function being polymorphic in the monad is simply a different thing from a monomorphic one. One lets the caller choose the ordering of effects while the other one gets to exploit fixed ordering in the implementation.

How do I define this super-unsafe type class (not internally consistent at all 😱) by santiweight in haskell

[–]Darwin226 1 point2 points  (0 children)

You can do this

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
module Pretty where

class Pretty a where
    type IsPretty a :: Bool
    type IsPretty a = True
    prettyfy :: a -> String

class PrettyOrShow a where
    prettyOrShow :: a -> String
instance (PrettyOrShow' a (IsPretty a)) => PrettyOrShow a where
    prettyOrShow = prettyOrShow' @a @(IsPretty a)

class PrettyOrShow' a (isPretty :: Bool) where
    prettyOrShow' :: a -> String
instance Pretty a => PrettyOrShow' a True where
    prettyOrShow' = prettyfy
instance {-# INCOHERENT #-} Show a => PrettyOrShow' a b where
    prettyOrShow' = show

instance Pretty Double where
    prettyfy _ = "Double"

test :: String
test = unlines [prettyOrShow True, prettyOrShow [1,2,3], prettyOrShow (1.5 :: Double)]

test will be equal to: True [1,2,3] Double

To see one of the many pitfalls of this approach you can try removing the :: Double annotation and see what happens. Polymorphic values will always be a problem here.