Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
    Double every other element of a list
    Deepak Kapiswe
    doubleElement = concatMap (\x->x:x:[])
    Actually meant (*2) every number
    But that
    Deepak Kapiswe
    then its very simple
    But that solution is good (bonus points for using infinite lists of functions)
    Deepak Kapiswe
    dE::(Num a)=> [a]->[a]
    dE = ((*2) <$>)
    How about doubling every OTHER element @deepakkapiswe_twitter :)
    (challenge: use lens)
    (challenge: make the offset (2) an argument)
    f 3 [1,11,111,1111,...] gives [2,11,111,2222,...]
    Olli Helenius
    f n = zipWith ($) (cycle ((*2) : replicate (n - 1) id))
    Great @liff !!
    Deepak Kapiswe
    but how to use lenses ... I have used lens only till (^. , %~ , .~ . , & )
    @liff Here is a lens solution in an old comment of mine
    I create an (indexed) traversal
    that focuses on every 2nd, 3rd, ... element
    >>> toListOf (every 1) [0..4]
    >>> toListOf (every 2) [0..4]
    >>> toListOf (every 3) [0..4]
    >>> itoListOf (every 2) "Hello"
    This is very powerful
    Where every has the definition
    every :: Int -> IndexedTraversal' Int [a] a
    every n = traversed.indices (n `divides`)
    Using operators
    >>> [0..4] ^.. every 1
    >>> [0..4] ^.. every 2
    >>> [0..4] ^.. every 3
    Deepak Kapiswe
    nice one ...
    but can you explain what is every
    Are you familiar with traversals?
    Deepak Kapiswe
    no not now ...
    a traversal can focus on many elements of a structure
    so if you use a regular traverse (or traversed) you are focusing on every element
    Continued in PM
    Hi. i want to send a email with Haskell and have here a copy of all code.

    Hi there ,

    i want to run a simple email sender with smtp from the Module :
    The Modul is already installed. cabal list --installed tells this !!!
    However, there is a compilation error that is asking for the Module :
    But cabal cannot FIND this module ! ANY IDEA WOULD HELP !

    Here is the example code of the session :

    import Network.HaskellNet.SMTP
    import Network.HaskellNet.Auth
    import qualified Data.Text.Lazy as T

    main = doSMTP "your.smtp.server.com" $ \conn ->
    authSucceed <- authenticate PLAIN "username" "password" conn
    if authSucceed
    then sendPlainTextMail "receiver@server.com" "sender@server.com" "subject" (T.pack "Hello! This is the mail body!") conn
    else print "Authentication failed."

    Here is the result of compilation with the right smtp data.

    $ ghc -o sendmail_4 sendmail_4.hs

    Could not find module `Network.HaskellNet.Auth'
    Use -v to see a list of the files searched for.

    cabal has listed the following Network Module :

    network installed version ,

    cabal install Network.HaskellNet.Auth does NOT work. cabal cannot FIND the Package , but normally AUTH should be IN the main Network Package that is already installed.
    hello guys!! im tryin to write a trade assistant plugin. anyone can send a transaction from A type client to B type client... can someone advise me a open source for that
    Jeyabalaji Subramanian
    Hello everyone
    I am new to Haskell. was looking for a simple yet elegant way to find whether a word contains alternate vowels.
    ram, rama, arav as inputs will return True. ramy would return False
    have broken this down into a series of checks on each letter which checks if the letter is a vowel
    Jeyabalaji Subramanian
    isVowel :: Char -> Bool isVowel x = x `elem` ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
    if you are evaluating "arjun", this will translate to: isVowel 'a' && not (isVowel 'r') && isVowel 'j' && not (isVowel 'u') && isVowel 'n'
    but not sure how to codify this. any help / hint is appreciated. thanks!
    Jeyabalaji Subramanian
    isVowel :: Char -> Bool
    isVowel x = x `elem` ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
    isNotVowel :: Char -> Bool
    isNotVowel x = not (isVowel x)
    recursiveAlternateVowels :: String -> Bool -> Bool
    recursiveAlternateVowels xs v = go xs v where
        go [] _ = True
        go (x:xs) True = isVowel x && go xs False
        go (x:xs) False = isNotVowel x && go xs True
    wordContainsAlternateVowels :: String -> Bool
    wordContainsAlternateVowels [] = True
    wordContainsAlternateVowels (x:xs)
        | isVowel x = recursiveAlternateVowels ([x]++xs) True
        | isNotVowel x = recursiveAlternateVowels ([x]++xs) False
    solved this using "inner" recursive functions, which was pointed out to me in the beginners channel.
    Hello, my teacher challenged me to show him the first 12 and last 12 digits of the result of the expression 2 ^ 17179869184. I already got the last 12 digits, I would like help to get the first 12 digits.
    Enzo Crance
    This might be a shorter solution for the problem from July 27th. Sorry for being late I just installed the app and I am new to Haskell.
    isVowel :: Char -> Bool
    isVowel = flip elem "aeiouAEIOU"
    checkAlternate :: (a -> Bool) -> [a] -> Bool
    checkAlternate p0 l = all id $ reverse bools
      where bools = snd $ foldl (\(p, acc) c -> (not . p, p c : acc)) (p0, []) l
    checkAlternateVowels :: String -> Bool
    checkAlternateVowels = checkAlternate isVowel
    Hello everyone ,
    I have a exercise for you guys, but don't know how to upload it here
    can you tell me how
    Can you guys convert this Java code into Haskell?
    int firstDuplicate(int[] a) {
        int n = a.length;
        boolean[] b = new boolean[n];
        for (int i = 0; i < n; i++) {
            if (b[a[i] - 1]) return a[i];
            b[a[i] - 1] = true;
        return -1;