pointfree

find unique matrices from a larger matrix

大憨熊 提交于 2019-12-11 13:35:54
问题 I'm fairly new the functional programming, so I'm going through some practice exercises. I want to write a function, given a matrix of unique naturals, let's say 5x5, return a collection of unique matrices of a smaller size, say 3x3, where the matrices must be intact, i.e. created from values that are adjacent in the original. 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Simple. Just slide across, then down, one by one in groups of 3, to get something that looks

Point-free: confused about where to put parenthesis

拈花ヽ惹草 提交于 2019-12-11 13:16:05
问题 let list_to_string = (String.concat "") (List.map (String.make 1));; This is wrong, but how do I make it understand that the argument is still to be supplied? The argument is expected to be of type char list , I.e. the first function that needs to be applied to it is the (List.map (String.make 1)) , and then pass it to String.concat "" . I think I've tried all combinations of parenthesis I could think of... no joy so far. Help? I also figured I could do it like this: let ($) f g x = f (g x);;

how can I pass argument (names) to a function operator? (point-free programming)

牧云@^-^@ 提交于 2019-12-11 04:54:30
问题 Background Say, I have a ClassA and ClassB , each of which require their own arguments in the respective constructor functions: ClassA <- function(A_arg1, A_arg2) { # some class-SPECIFIC construction magic happens, say out <- list(A_arg1, A_arg2) # some GENERAL construction magic happens class(out) <- "ClassA" return(out) } ClassB <- function(B_arg1, B_arg2) { # some class-SPECIFIC construction magic happens, say out <- B_arg1 + B_arg2 # some GENERAL construction magic happens class(out) <-

Why does changing sq to point-free change the type [duplicate]

不打扰是莪最后的温柔 提交于 2019-12-11 02:23:23
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: What is going on with the types in this ghci session? To try and practice a bit of haskell and learn about point free I was playing around with a function to square a number so I started by defining >let dup f x = f x x so I could rewrite sq in terms of dup (without worrying about making dup point free for now) >let sq x = dup (*) x and checking the type of sq I see what I'm expecting to see >:t sq >sq :: Num

Haskell Type Error From Function Application to Function Composition

自闭症网瘾萝莉.ら 提交于 2019-12-11 01:41:43
问题 This question is related to this Function Composition VS Function Application which answered by antal s-z. How you can get this ? map has type (a -> b) -> [a] -> [b] head has type [a] -> a map head has type [[a]] -> [a] Why the following code has type error for function composition ? test :: [Char] -> Bool test xs = not . null xs getMiddleInitials :: [String] -> [Char] getMiddleInitials middleNames = map head . filter (\mn -> not . null mn) middleNames but this does not have type error

Haskell: mapping function application

自闭症网瘾萝莉.ら 提交于 2019-12-10 10:15:22
问题 Part of some computation I am doing in Haskell results in a list of functions that map Float to Float . I'd like to apply a single argument to all these functions, like so: -- x :: Float -- functions :: [Float -> Float] map (\f -> f x) functions Is there a way to do this without making use of a throw-away lambda function? I've searched Hoogle for what I think the signature should be ( [a -> b] -> a -> [b] ) with no luck. 回答1: You can use the $ operator, which is just function application: map

Write f in pointfree-style?

风格不统一 提交于 2019-12-10 09:21:09
问题 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't figure out how to do the more general case. 回答1: We have: k x y = (f (g x)) (h y) and we wish to write k in point-free style. The first argument passed to k is x . What do we need to do with x ?

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