logo
down
shadow

Don't know how to use . and $ operator in Haskell


Don't know how to use . and $ operator in Haskell

By : lvl4ul2i
Date : November 18 2020, 01:01 AM
will help you I do not see a way of using ($) and (.) in this code.
However, you can simplify your code as this:
code :
compress :: [Char] -> [Char]
compress [] = []
compress as@(x:xs)
    | g as 1 == 1 = x : compress xs
    | otherwise = x : show (g as 1) ++ compress (drop (g as 1) as)

g :: [Char] -> Int -> Int
g (a:as) i
    | a == head as = g as (i + 1)
    | otherwise = i
g _ i = i

main = getLine >>= putStrLn . compress
[head as] ++ compress (drop 1 as)
head as : compress (drop 1 as)
x : compress xs
compress :: [Char] -> [Char]
compress = concatMap (\x -> head x : show (length x)) . group
compress :: [Char] -> [Char]
compress xs = concat $ map (\x -> head x : show (length x)) $ group xs
compress :: [Char] -> [Char]
compress xs = concatMap (\x -> head x : show (length x)) (group xs)
capitalizeWords :: String -> String
capitalizeWords string = unwords (map (\(f:rest) -> toUpper f : rest) (words string))

main = putStrLn (capitalizeWords "here you are")
capitalizeWords :: String -> String
capitalizeWords = unwords . map (\(f:rest) -> toUpper f : rest) . words

main = putStrLn $ capitalizeWords "here you are"
capitalizeWords string = unwords $ map (\(f:rest) -> toUpper f : rest) (words string)
capitalizeWords string = unwords $ map (\(f:rest) -> toUpper f : rest) $ words string


Share : facebook icon twitter icon
cabal install libClang (Haskell) dont work under minGW

cabal install libClang (Haskell) dont work under minGW


By : user3056016
Date : March 29 2020, 07:55 AM
wish of those help It will be a matter of setting the paths to the library, so the compiler can find it. You may be able to set
code :
 LIBRARY_PATH
Haskell code errors - I dont understand what it is asking for

Haskell code errors - I dont understand what it is asking for


By : Vignesh Ramesh
Date : March 29 2020, 07:55 AM
hop of those help? You say that you want a function that returns the first component of the second element of the list. The best way to write this function will be by pattern matching. But first, let's think about its type.
Say you want a list of tuples of (Int,Char). This is written as [(Int,Char)]. If you want a list of 2-tuples of arbitrary type, you replace the types Int and Char with type variables, so you end up with the type [(a,b)].
code :
f :: [(a,b)] -> a
g :: [a] -> a
g xs = head (tail (tail xs))
g :: [a] -> a
g (x : y : z : []) = z
g :: [a] -> a
g (x : y : z : rest) = z
g :: [a] -> a
g (_ : _ : z : _) = z
f :: [(a,b)] -> a
f ( (w,x) : (y,z) : rest ) = y
f :: [(a,b)] -> a
f ( _ : (y,_) : _) = y
ghci> f [(5,'b'),(1,'c'),(6,'a')]
1
Error in overloading << operator in cpp ? dont know why?

Error in overloading << operator in cpp ? dont know why?


By : E-ron Ale
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further You should always return the stream reference, not the point reference.
Update: I think someone else pointed out the actual problem in the comments (istream instead of ostream). Also, you are passing the streams by value instead of by reference. Here is what your code should look like:
code :
istream& ::operator >> (istream &in, const point &obj)
{
    in >> obj.x;
    in >> obj.y;
    return in;
}
ostream& ::operator << (ostream &out, const point &obj)    // <--- Here is the Problem
{
    out << "( " << obj.x << " , " << obj.y << " )";
    return out;
}
Haskell Caesar Cypher, I dont get interpreter errors

Haskell Caesar Cypher, I dont get interpreter errors


By : user2055873
Date : March 29 2020, 07:55 AM
this will help As Jeff Burka says, you need Char not char to get the code to compile.
You can also simplify some of the parentheses - using HLint (which is built into IDEs like EclipseFP) is very helpful here:
code :
cipher :: String -> Int -> String
cipher [] _ = []
cipher ch n = chr ((ord (head ch) - n) `mod` 26) : cipher (tail ch) n
cipher (h:t) n = chr ((ord h - n) `mod` 26) : cipher t n
cipher2 [] _ = []
cipher2 c n = map shift c
  where 
    a = ord 'A'
    shift ch = chr (((ord ch - a + n) `mod` 26) + a)
> cipher2 "ABCDE" 1
"BCDEF"
> cipher2 "ABCDE" 26
"ABCDE"
Is Haskell's bind operator (>>=) equivalent to F#'s forward pipe operator (|>)?

Is Haskell's bind operator (>>=) equivalent to F#'s forward pipe operator (|>)?


By : cora
Date : March 29 2020, 07:55 AM
Hope this helps Not really. If you specialize m to IO, then there are some superficial similarities, so maybe it’s true that (>>=) @IO is sort of like F#’s |>, but in general, the similarity does not hold.
If we specialize m to Maybe, then >>= is like Option.bind, just with the arguments flipped (which makes sense, since >>= is pronounced “bind”).
code :
ghci> Just [1, 2, 3] >>= headMay
Just 1
ghci> Just [] >>= headMay
Nothing
ghci> Nothing >>= headMay
Nothing
p :: Parser Char
p = anyChar >>= \c -> if isDigit c then digit else anyChar
f :: Key -> String
g :: String -> Key -> Char
h :: Char -> Key -> Bool
ghci> :t f >>= g >>= h
f >>= g >>= h :: Key -> Bool
(&) :: a -> (a -> b) -> b
Related Posts Related Posts :
  • What are the pitfalls of using FlexibleContexts and FlexibleInstances?
  • Histomorphism a la Mendler
  • Haskell Shelly sample code
  • Finding type signatures in Haskell that are too specific
  • haskell - will pattern matching work faster for non-specific form of an algebraic data type?
  • Cannot enter multiline statements in GHCi
  • Using Gloss to run a simulation while using SDL to play a sound
  • Haskell - Calculating the shortest path using trees
  • Beginner: Converting Types in Haskell
  • G-machine, (non-)strict contexts - why case expressions need special treatment
  • Indentation with Let Statements
  • Haskell parse list of integers with Attoparsec
  • Change (0, 1] to (0, 1) without branching
  • Haskell equivalent to contains
  • Is there a way to unmap in Haskell?
  • Using HLint.hs file in EclipseFP
  • Why is my haskell code so slow
  • How is FRP handled in terms of memory?
  • Generalizing traversal of expressions with changes on specific nodes
  • Why does pattern matching on this GADT seem to introduce ambiguity in the type checker?
  • How to detect end of input with pipes
  • Basic Haskell IO Monad FilePath join
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org