## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
Baldur
Hi
Double every other element of a list
Deepak Kapiswe
doubleElement::[a]->[a]
doubleElement = concatMap (\x->x:x:[])
Baldur
Actually meant (*2) every number
But that
Deepak Kapiswe
then its very simple
Baldur
But that solution is good (bonus points for using infinite lists of functions)
Deepak Kapiswe
dE::(Num a)=> [a]->[a]
dE = ((*2) <$>) Baldur @Iceland_jack_twitter 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 @liff f n = zipWith ($) (cycle ((*2) : replicate (n - 1) id))
Baldur
Great @liff !!
Deepak Kapiswe
but how to use lenses ... I have used lens only till (^. , %~ , .~ . , & )
Baldur
@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]
[0,1,2,3,4]
>>> toListOf (every 2) [0..4]
[0,2,4]
>>> toListOf (every 3) [0..4]
[0,3]
>>> itoListOf (every 2) "Hello"
[(0,'H'),(2,'l'),(4,'o')]
This is very powerful
Baldur
Where every has the definition
every :: Int -> IndexedTraversal' Int [a] a
every n = traversed.indices (n divides)
Using operators
>>> [0..4] ^.. every 1
[0,1,2,3,4]
>>> [0..4] ^.. every 2
[0,2,4]
>>> [0..4] ^.. every 3
[0,3]
Deepak Kapiswe
nice one ...
but can you explain what is every
Baldur
Are you familiar with traversals?
Deepak Kapiswe
no not now ...
Baldur
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
Baldur
Continued in PM
Senenmut
@Senenmut
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 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

sendmail_4.hs:2:8:
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 2.4.1.2 , 2.6.3.3 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. juliopc @juliopc 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 @jeyabalajis 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 @jeyabalajis 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 @jeyabalajis 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. Ana @anabeatrizzz 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 @cl0udyhug_twitter 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
Rita123-j
@Rita123-j
Hello everyone ,
I have a exercise for you guys, but don't know how to upload it here
can you tell me how
Microtribute
@Microtribute
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;
}`