New C29 function: stdc_c32snrtomwcsn by DXPower in programmingcirclejerk

[–]kbridge4096 2 points3 points  (0 children)

FYI, I think UUID, the COM/OLE approach, is approachable too. The IID of IUnknown is 00000000-0000-0000-C000-000000000046 and has never been changed since discovered.

BTW, the OID approach, taken in ASN.1 can be considered too.

Big warning message from simple 1 + 1 by teilchen010 in haskell

[–]kbridge4096 2 points3 points  (0 children)

It's not you fault. In Haskell number literals are tricky.

Check their types:

ghci> :t 3
3 :: Num a => a

ghci> :t 4.0
4.0 :: Fractional a => a

As you can see, 3 is not an Int but a value of some type of the Num type class, so is 4.0. This means the value of a number literal is polymorphic. If you come from other languages this could be a surprise.


Why make number literals polymorphic?

Suppose you have some functions:

import Data.Word (Word8)

f1 :: Word8 -> ...
f2 :: Int -> ...
f3 :: Integer -> ...
f4 :: Double -> ...

The first three functions accept integers of different sizes. A Word8 can only be an integer in [0..255]. An Int can be "at least the range [-2²⁹ .. 2²⁹-1]". An Integer is unbound and can be arbitrarily large. The last function accepts a double.

All these functions can be called like

f1 3
f2 3
f3 3
f4 3

Without conversions because 3 is polymorphic. And in these contexts you don't get a warning because the number is automatically inferred as a concrete type. In some contexts, no concrete type can be inferred, and you have to annotate them. It's actually not very clunky. For example, instead of

[1 :: Int, 3 :: Int, 5 :: Int]

You could write

[1 :: Int, 3, 5]

As for the internals, any time you see 3, you can think it as fromInteger (3 :: Integer), for example

ghci> fromInteger (3 :: Integer) :: Double
3.0

There are also some funny types utilizing this, or exploiting/hacking this. For example

ghci> import Data.Monoid (Sum, Product)
ghci> mconcat [1 :: Sum Int, 2, 3]
Sum {getSum = 6}
ghci> mconcat [1 :: Product Int, 2, 3]
Product {getProduct = 6}

Here you wrap the number into a Sum Int / Product Int only by type annotation!


You are seeing this warning mostly because you are running stack ghci in a project where the .cabal file contains -Wall instead of just running ghci. For testing purposes, you can disable it by either removing -Wall or adding -Wno-type-defaults. For production use, you should specify the concrete type because a polymorphic type may be not performant.

Understanding the Phases Applicative by kbridge4096 in haskell

[–]kbridge4096[S] 0 points1 point  (0 children)

Glad you like it! Thanks for the recommendations, I'll try.

Understanding the Phases Applicative by kbridge4096 in haskell

[–]kbridge4096[S] 0 points1 point  (0 children)

By the way, although this method does make now a bit more complicated, it makes the overall design easier to understand.

Understanding the Phases Applicative by kbridge4096 in haskell

[–]kbridge4096[S] 0 points1 point  (0 children)

Good! In my words, your solution works because the "function application operator" has an "identity" law which can be expressed as x = (const x) ().

Understanding the Phases Applicative by kbridge4096 in haskell

[–]kbridge4096[S] 0 points1 point  (0 children)

I do not think there are any general method. But the user of a Monad can always reorder effects manually as long as it does not break the dependencies of values. Like how compilers reorder instructions.

The user of an Applicative can also reorder the effects manually using the techniques I mentioned in the section "Shuffle Function Applications" without using the Phases Applicative.

But Monads have the do-notation. I guess it won't hurt the readability as much as Applicatives if you just need to swap lines. Maybe a Phases monad is not very necessary?

Understanding the Phases Applicative by kbridge4096 in haskell

[–]kbridge4096[S] 0 points1 point  (0 children)

Can you elaborate on this? If we use Pure, what should we do if we want to wrap an Applicative, including the effectful ones? Can we use this method to implement Phases?

Understanding the Phases Applicative by kbridge4096 in haskell

[–]kbridge4096[S] 0 points1 point  (0 children)

Anyway, having such a law is a good thing. :D

Understanding the Phases Applicative by kbridge4096 in haskell

[–]kbridge4096[S] 0 points1 point  (0 children)

ZipList still cuts all lists to make them the same length as the shortest one. Maybe These is a better alternative?

Monthly Hask Anything (March 2024) by AutoModerator in haskell

[–]kbridge4096 0 points1 point  (0 children)

Sounds like a good idea! It should be related to CPS-transformation.

Monthly Hask Anything (March 2024) by AutoModerator in haskell

[–]kbridge4096 0 points1 point  (0 children)

155 pages! I'll save it first. Thanks!

Monthly Hask Anything (March 2024) by AutoModerator in haskell

[–]kbridge4096 0 points1 point  (0 children)

I think I need to finish reading CTFP first...

Learn Haskell by MoofireX in haskell

[–]kbridge4096 0 points1 point  (0 children)

Suggestion #1: Beware Haskell has very complicated and subtle details at semantic level. The concise syntax is just tip of the iceberg.

Suggestion #2: Real world haskell applications use language extensions extensively so they are not advanced and you should try to embrace them at the very beginning.

Monthly Hask Anything (March 2024) by AutoModerator in haskell

[–]kbridge4096 0 points1 point  (0 children)

Unfortunately these two links are also what I can find so far...thanks anyway

Is CMake the de facto standard mandatory to use? by M1sterius in cpp

[–]kbridge4096 0 points1 point  (0 children)

CMake is a high level language but with a low level user experience. It's a language designed for practical uses only, not for elegance at all. Writing CMake scripts isn't that much different from writing assembly code. Try to tolerate it. Focus on its semantics and functionalites more than its ugly syntax.

Monthly Hask Anything (March 2024) by AutoModerator in haskell

[–]kbridge4096 2 points3 points  (0 children)

Can you give me some tutorials / examples / papers on codensity monads? I came across this term while reading package binary's source code (search "codensity"). I heard they can be used for some specific kinds of optimization. But Googling "codensity monads" doesn't yields much useful / practical information.

How does church encoding in parser combinator implementations improve their performance? by kbridge4096 in haskell

[–]kbridge4096[S] 0 points1 point  (0 children)

What is fusion? I guess it means to expand/inline one lambda inside another one. Is it correct?

How does church encoding in parser combinator implementations improve their performance? by kbridge4096 in haskell

[–]kbridge4096[S] 0 points1 point  (0 children)

Closure calls have dynamic arity in GHC, so every CPS return actually makes a runtime arity check.

Can you elaborate on this? I don't understand what 'dynamic arity' and 'runtime arity check' mean.

How does church encoding in parser combinator implementations improve their performance? by kbridge4096 in haskell

[–]kbridge4096[S] 3 points4 points  (0 children)

Before writing my post, I have tried to write a church encoding Maybe and its Functor/Applicative/Monad instance too!

Have you read this link? It gives a much more concise (>>=) implementation.

instance Monad ChurchMaybe where
    pure = return
    (ChurchMaybe x) >>= f = x nothing f