How do I write a function that takes any integers in a list and produces the number of values in the list whose one's digit (i.e. the least significant or rightmost digit) is 1. For example,
(ones (list 82 231 1 22 1000)) => 2?
instance Monad m => Monad (MaybeT m) where
return = MaybeT . return . Just
instance Monad m => MonadPlus (MaybeT m) where
mzero = MaybeT $ return Nothing
mplus x y = MaybeT $ do maybe_value <- runMaybeT x
case maybe_value of
Nothing -> runMaybeT y
Just value -> runMaybeT x
instance MonadTrans MaybeT where
lift = MaybeT . (liftM Just)
getValidPassword :: MaybeT IO String
getValidPassword = do s <- lift getLine
guard (isValid s)
return s
askPassword :: MaybeT IO ()
askPassword = do lift $ putStrLn "Insert your new password:"
value <- getValidPassword
lift $ putStrLn "Storing in database..."
Haskell doesn't have subtype polymorphism and can only emulate dependent types. Unique types are in Clean, but not Haskell. And I don't think haskell has the principle type property.
Name:
Anonymous2013-01-10 14:06
shift :: ((a -> r) -> Cont r r) -> Cont r a
shift e = cont $ \k -> reset (e k)
reset :: Cont a a -> a
reset e = e `runCont` id
in lisp?
Name:
Anonymous2013-01-10 14:09
This actually is quite retarded:
newtype (Monad m) => MaybeT m a = MaybeT { runMaybeT :: m (Maybe a) }
It is a pain in the ass, and if you switched to a cps'ed version of the MaybeT monad, you don't care anymore if it is a monad or not.
>>13
Actually it's an easy fix, I feel stupid. (define (one? n) (= 0 (remainder (- (abs n) 1) 10)))
Name:
Anonymous2013-01-10 14:57
In your declarative next-generation non-shit programming language that currently doesn't exist outside your brain, should cardinals (and thus the entire numerical tower) be defined in terms of Church numerals?
#include <stdio.h>
#define SILLY_MAX_HEAP_BETTER 100
int main (void)
{
long int le-numbers[SILLY_MAX_HEAP_BETTER];
int counter = 0;
short int le_great_decimal, tmp_holder;
char terminator;
printf("Tell me the number goyim.");
do {
scanf("%d%c", &le_numbers, &terminator);
counter++;
}while (terminator != EOF);
for (int i = 0; i < counter; i++)
{
tmp_holder = le_numbers[i] % 10;
if (tmp_holder > le_great_decimal)
le_great_decimal = tmp_holder;
}
printf(\nHere is your silly number: %d", le_great_decimal);
return 0;
}
>>28-30
Sorry it was terrible in all ways.
(define (one? n) (= 0 (remainder (- (abs n) 1) 10)))
(define (ones l) (foldl (λ (e c) (if (one? e) (+ c 1) c)) 0 l))
Name:
Anonymous2013-01-10 23:35
>>31
Is there a way to do this without using lambda?