Can F# be refactored into a pointfree style?

女生的网名这么多〃 提交于 2019-12-08 19:39:43
问题 In researching a topic related to programming I came across a pointfree refactoring tool for Haskell in the lambdabot and was wondering if F# can be refactored into a pointfree style? I am not advocating the use of pointfree style, but see it as a means to better comprehend a function. Note: pad answered an earlier version of this question, but I reworded this question as the answer is of value to others learning and using F# and I did not want this to be deleted because of some close votes.

How does the expression `ap zip tail` work

爷,独闯天下 提交于 2019-12-08 15:26:35
问题 I wondered how to write f x = zip x (tail x) in point free. So I used the pointfree program and the result was f = ap zip tail . ap being a function from Control.Monad I do not understand how the point free definition works. I hope I can figure it out if I can comprehend it from the perspective of types. import Control.Monad (ap) let f = ap zip tail let g = ap zip :info ap zip tail f g ap :: Monad m => m (a -> b) -> m a -> m b -- Defined in `Control.Monad' zip :: [a] -> [b] -> [(a, b)] --

Point free style with infix notation

十年热恋 提交于 2019-12-07 20:09:35
问题 Hello is there a way to write point free style when using infix notation? f::Int->Int->Int->Int f a b=(+) (a+b) Why you cannot do something like this ? f::Int->Int->Int->Int f a b=(a+b) + or f a b= (a+b) `+` Can you not combine operators in point free style like e.g? ptfree::Int->Int->Int->Int ptfree=(+) (+) I mean you can chop arguments of functions like fold but why not for operator arguments? 回答1: Well since you need to pass two parameters, we can use what is known as the " surprised owl

Point-free lens creation does not type check

筅森魡賤 提交于 2019-12-07 04:07:02
问题 In the function test , I traverse over a list, generate lenses from it's members, and then print some data. This works when I use a pointful call style. It fails to typecheck when I make it point-free. Why is this the case, and how can I solve this problem? It looks like to me that GHC is not retaining the information that the higher-ranked f (in the lens) is a Functor when using point-free style, but I'm not too sure. I'm using GHC 7.8.3 {-# LANGUAGE RankNTypes #-} {-# LANGUAGE

Number of arguments and point-free in Haskell [duplicate]

爱⌒轻易说出口 提交于 2019-12-06 17:30:31
问题 This question already has answers here : Defining a function by equations with different number of arguments (3 answers) Closed 2 years ago . With multiple pattern-matching, different numbers of arguments are impossible, even with point-free! foo True b = b + 2 foo _ = id doesn't work for example. But foo True = (+2) foo _ = id does. Sometimes we can use point-free only in one part of the function, so... Why? Is it too hard for GHC? :'( 回答1: Why? Is it too hard for GHC? No . It is not at all

Write f in pointfree-style?

穿精又带淫゛_ 提交于 2019-12-05 16:05:03
Say I have functions g :: a -> b, h :: a -> c and f :: b -> c -> d. Is it possible to write the function f' :: a -> a -> d given by f' x y = f (g x) (h y) in point free style?. One can write the function f' a -> d, f' x = f (g x) (h x) in point free style by setting f' = (f <$> g) <*> h but I couldn

Is there a point-free way to convert a conditional check into a Maybe type of the input?

本小妞迷上赌 提交于 2019-12-05 08:13:07
I am just working through some simple exercises in haskell and was wondering if there was a point-free way of converting an if-then-else statement into a Maybe type: Nothing being returned if the condition is false, and Just the input if the condition is true. In short, given some: maybeIf :: (a ->

What is the derivation that shows Haskell's \\x -> (x, x) equivalent to join (,)?

邮差的信 提交于 2019-12-04 23:56:37
According to pointfree : \x -> (x, x) is equivalent to: join (,) What is the derivation that shows this? Look at the type signatures: \x -> (x, x) :: a -> (a, a) (,) :: a -> b -> (a, b) join :: Monad m => m (m a) -> m a It should be noted that ((->) r) is an instance of the Monad typeclass. Hence,