HN user

sudomakeup

20 karma
Posts0
Comments22
View on HN
No posts found.

You can do left to right function composition with (>>>)

Given functions f, g , h,

h >>> g >>> f is equivalent to f . g . h

Its from Control.Category, so it generalizes to other things, but for functions specifically its left to right composition.

( theres also (<<<), which in this case is identical to (.) )

( Also present in Control.Arrow . Why? I dont know this topic well enough to explain. My understanding is limited to what these operators mean in the specific of functions. Functions(->) are a type as well, so they can be instances of typeclasses. for example

  instance Functor ((->) r) where  
        fmap = (.)

)
Inventing Monads 6 years ago

So, I'm a bit rusty on haskell but I have some notes on a similar concept. Essentially, fmap with a twist - instead of applying the same function to a list of values, you have a list of functions that you want to evaluate on the same value. "fpam". In this case, we're dealing with a list of size 2

  fpam :: [(a -> b)] -> a -> [b]
  fpam fns v = fns <*> pure v
after that then fold the list with boolean &&
  foo :: (a -> Bool) -> (a -> Bool) -> a -> Bool
  foo f g x = foldr1 (&&) ( fpam [f,g] x)
or alternatively with no helper functions
  foo2 :: (a -> Bool) -> (a -> Bool) -> a -> Bool
  foo2 f g x = foldr1 (&&) ( [f,g] <*> pure x)
for example
  Prelude> foldr1  (&&) ( [ (==3), (==4) ]  <*> pure 3 )
  False
Alternate implementations:
    import Data.List
    import Data.Function
    import Control.Monad.State
    import Data.Foldable
    import Control.Arrow((>>>))
    import Control.Monad.Reader
    import Control.Monad.List

    applyList :: [(a -> a)] -> a -> a
    applyList list = execState $ for_ list modify

    applyList2 :: [(a -> a)] -> a -> a
    applyList2 = foldr1 (>>>) 

    fpam :: [(a -> b)] -> a -> [b]
    fpam fns v = fns <*> pure v

    fpam2 :: [(a -> b)] -> a -> [b]
    fpam2 fns = runReader $ forM fns reader

    fpam3 :: [(a -> b)] -> a -> [b]
    fpam3 fns v = fmap (\f -> f v) fns

    fpam4 :: [(a -> b)] -> a -> [b]
    fpam4 fns = runReaderT $ do
      fn <- lift fns
      reader fn

Well, the python interpreter has a main function.

This whole topic is like comparing apples to oranges. The python interpreter(which IS compiled and has a main function) defines the rules of whats required in python. And it can reasonable assume that the entry point is the beginning of the .py file its running.

Mach kernel 7 years ago

I dont recall if it was Apple that did this, but theres trick one can pull with an "open source"codebase thats part of a proprietary product.

One can have said codebase effectively outsource functionality to function calls on closed source libraries.

Google does something similar with android except in that case its moreso coupling functionality to their services:

https://arstechnica.com/gadgets/2018/07/googles-iron-grip-on...

In the disassembly we can see a bunch of fine grained operations but the meaning behind them is opaque. For example, we see two array access operations but its not clear what they do. They might look like this:

mov al, [array + ebx]

Considering the assert statement from point 2: "plr[myplr].InvGrid[i] <= plr[myplr]._pNumInv"

From this we can see what the variables were named in the source code. Assuming "plr" = player and "InvGrid" = Inventory grid, we can deduce one the array access operations is to get the current player and another is for getting an item from the inventory grid.

Dark Patterns 8 years ago

This is somewhat covered by https://darkpatterns.org/types-of-dark-pattern/roach-motel

Gyms are notorious for this. Almost any staff member can sign someone up, but if you want to cancel theres only one guy in the entire gym authorized to do that, and they are frequently "out to lunch".

Either that or you have to print a cancellation form and send it by snail mail with 30 days notice. And if you dont send by certified mail they will claim they never received it.

You can still have mutable references and impure functions in Haskell, but its not like "path of least resistance" of other languages. The IO type marks impure functions

Also one can use STRef if they want to have a pure function that is internally implemented with mutable values - that is all the side effects are self contained.

http://gamasutra.com/view/news/169296/Indepth_Functional_pro...

"a function can still be pure even if it calls impure functions, as long as the side effects don't escape the outer function"