Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-8081-120121-160161-

Is Haskell ENTERPRISE yet?

Name: Anonymous 2011-04-24 7:00

Well, is it?


data Suit = Clubs|Diamonds|Hearts|Spades
    deriving (Bounded, Enum, Eq, Ord, Show) -- Suit ordering for disambiguation, same as in bridge.
data CardRank = Two|Three|Four|Five|Six|Seven|Eight|Nine|Ten|Jack|Queen|King|Ace
    deriving (Bounded, Enum, Eq, Ord, Show)

data Card = Card {rank::CardRank, suit::Suit} deriving (Eq,Bounded)
instance Enum Card where
    -- Enumeration chosen for practicality; it scales automatically for decks with more or less than thirteen cards per suit.
    succ (Card rank suit)
        | rank==maxBound = Card minBound (succ suit)
        | otherwise = Card (succ rank) suit
    pred (Card rank suit)
        | rank==minBound = Card maxBound (pred suit)
        | otherwise = Card (pred rank) suit
    toEnum x = Card (toEnum rank) (toEnum suit) where
        (suit,rank)=x`divMod`cardinality
        cardinality = (fromEnum (maxBound::CardRank)) + 1
    fromEnum (Card rank suit)= fromEnum rank + (fromEnum suit)*cardinality where
        cardinality = (fromEnum (maxBound::CardRank)) + 1
instance Show Card where
    show (Card rank suit) = show rank ++" of "++ show suit
instance Ord Card where
    compare (Card rank0 suit0) (Card rank1 suit1)
        | rank0 == rank1 = compare suit0 suit1 --Again, for disambiguation.
        | otherwise      = compare rank0 rank1

type Hand = [Card] -- A hand should have five cards.
type Deck = [Card] -- A deck can be of arbitrary size.

data Rank =
     HighCard Card
    |Pair CardRank
    |TwoPairs CardRank CardRank --Higher pair first
    |ThreeOfAKind CardRank
    |Straight CardRank --Highest card
    |Flush Card
    |FullHouse CardRank CardRank --Three of a kind first, pair second.
    |FourOfAKind CardRank
    |StraightFlush Card
    |RoyalFlush Suit
    deriving (Eq, Ord)
   
instance Show Rank where
    show (HighCard (Card rank _)) = show rank++" High"
    show (Pair rank)
        |rank==Six = "Pair of Sixes"                   -- check 'em dubz
        |otherwise= "Pair of "++show rank++"s"
    show (TwoPairs rank0 rank1)
        | rank0 == Six = "Sixes and "++show rank1++"s" -- nice, lol
        |rank1 == Six = show rank0++"s and Sixes"
        |otherwise = show rank0++"s and "++show rank1++"s"
    show (ThreeOfAKind rank)
        |rank==Six = "Three Sixes"
        |otherwise= "Three "++show rank++"s"
    show (Straight rank) =  "Straight to the "++show rank
    show (Flush (Card rank suit))= show rank++"-high Flush of "++show suit
    show (FullHouse rank0 rank1)
        |rank0==Six = "Sixes full of "++show rank1
        |rank1==Six = show rank0 ++"s full of Sixes"
        |otherwise = show rank0 ++"s full of "++show rank1++"s"
    show (FourOfAKind rank)
        |rank==Six = "Quadruple Sixes"
        |otherwise = "Quadruple "++show rank++"s"
    show (StraightFlush (Card rank suit))
        |rank==Five = show suit ++" Steel Wheel"
        |otherwise = show suit ++ " Flush Straight to the "++show rank
    show (RoyalFlush suit) = "Royal Flush of "++show suit

rankHand::Hand -> [Rank]
rankHand hand@([a@(Card rankA suitA), b@(Card rankB suitB), c@(Card rankC suitC), d@(Card rankD suitD), e@(Card rankE suitE)])
    | royalFlush                  = [RoyalFlush suitA]
    | steel    && flush           = StraightFlush y:(map HighCard singles)
    | straight && flush           = [StraightFlush z]
    | fourAtFirst                 = (FourOfAKind rankU):[HighCard z]
    | fourAtLast                  = (FourOfAKind rankZ):[HighCard u]
    | threeAtFirst && pairAtLast  = [FullHouse rankU rankZ]
    | threeAtLast  && pairAtFirst = [FullHouse rankZ rankU]
    | steel                       = [Flush y]
    | flush                       = [Flush z]
    | straight                    = [Straight rankZ]
    | length trips > 0            = ThreeOfAKind (rank $ head trips):(map HighCard $ reverse singles)
    | length dubz == 1            = Pair (rank dub):(map HighCard (reverse singles))
    | length dubz == 2            = TwoPairs (rank $ head dubs) (rank dub):(map HighCard singles)
    | otherwise                   = map HighCard $ reverse sortedHand where
        [u@(Card rankU _),_,_,y,z@(Card rankZ _)] = sortedHand
        (dub:dubs) = dubz
        sortedHand     = sort hand
        sortedRanks    = map rank sortedHand
        groupedByRanks = map (\rank->(length rank, last rank)) $ groupBy (\(Card rank0 _) (Card rank1 _)->rank0==rank1) sortedHand
        tri n r = isInfixOf (take n $ repeat r) $ sortedRanks
        get n = map (\(_,b)->b) $ filter (\(a,_)->a==n) groupedByRanks
        dubz    = get 2
        trips   = get 3
        singles = get 1
        royalFlush = sortedHand==([Card Ten suitA..Card Ace suitA])
        flush      = map suit hand == (take 5 $ repeat suitA)
        straight   = [rankU..rankZ] == sortedRanks
        steel      = [Two .. Five] ++ [Ace] == sortedRanks
        fourAtFirst  = tri 4 rankU
        fourAtLast   = tri 4 rankZ
        threeAtFirst = tri 3 rankU
        threeAtLast  = tri 3 rankZ
        pairAtLast   = tri 2 rankZ
        pairAtFirst  = tri 2 rankU
rankHand _ = []

Name: Anonymous 2011-04-24 7:06

That was Terrible!

Name: Code Less, Create More 2011-04-24 7:15

Lisp:

yoba n -> a:[0..n+1] for (i:1; i<=n; !i+1) a,i =: i-a,(a,(i-1)) -> a,n


Haskell

import  Data.Array.IO
 
a :: IOArray Int (Maybe Int) -> Int -> IO Int
a st n = do
  an  <- get st $ n - 1
  ann <- get st $ an
  return $ n - ann
 
get :: IOArray Int (Maybe Int) -> Int -> IO Int
get _  1 = return 1
get st n = do
  val <- readArray st n
  case val of
    Nothing -> do
                 v <- a st n
                 writeArray st n $ Just v
                 return v
    Just v  -> return v
 
main :: IO ()
main = do
  let n = 2012
  st <- newArray (1,n) Nothing :: IO (IOArray Int (Maybe Int))
  val <- a st n
  print val

Name: Anonymous 2011-04-24 7:17

>>3
FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU

Name: Anonymous 2011-04-24 7:27

IM IN UR MOMAD INVOKIN UR KONTINUATIONS!!1

Name: Can you spot the error? 2011-04-24 7:41


$ ghci
GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
^[[ALoading package base ... linking ... done.
Prelude> let fac 1 = 1; fac n = n * fac n-1
Prelude> fac 4
*** Exception: stack overflow
Prelude>

Name: Anonymous 2011-04-24 7:50

>>6

Prelude> let f 1 = 1; f n = ((*) (n) ((f) ((-) n 1)))
Prelude> ((f) 4)
24


Now it works!

Name: Anonymous 2011-04-24 8:03

>>7
or just

Prelude> let fac 1 = 1; fac n = n * fac (n-1)

Function application has higher precedence than operators.

Name: Anonymous 2011-04-24 8:04

>>8
why?

Name: Anonymous 2011-04-24 8:06

>>9
why not? Somethings can be written more nicely like this (like using currying and composition together), others can't. Matter of taste really.

Name: Anonymous 2011-04-24 8:07

>>9
http://book.realworldhaskell.org/read/getting-started.html
It is sometimes better to leave at least some parentheses in place, even when Haskell allows us to omit them. Complex expressions that rely completely on operator precedence are notorious sources of bugs. A compiler and a human can easily end up with different notions of what even a short, parenthesis-free expression is supposed to do. There is no need to remember all of the precedence and associativity rules numbers: it is simpler to add parentheses if you are unsure.

Name: Anonymous 2011-04-24 8:08

>>3

#lang racket
(define (LOL)
        (display "lol") (OLO))
(define (OLO)
        (display "olo") (LOL))
(LOL)

Name: Anonymous 2011-04-24 8:09

>>10
For example when i wanna partially apply functions within a chain of compositions like so:

foldl1 baz . foo . map bar . foobar

Name: Anonymous 2011-04-24 9:08

>>13
Foldl1? considered harmful. Use foldl', foldl1' instead.

Name: Anonymous 2011-04-24 11:59

Oh.
>>3
yoba
You are from 0chan.ru, aren't you?

Name: Anonymous 2011-04-24 12:22

>>15
Explanation for non-outsiders of what that means?

Name: Anonymous 2011-04-24 15:20

>>16
Non-outsiders require no explanation.

Name: Anonymous 2011-04-25 0:25

If you want to interoperate with code written in other languages then functional languages like OCaml and Haskell are *less* safe than the JVM and CLR because their FFIs are comparatively poorly designed and poorly implemented.

Name: Anonymous 2011-04-25 0:29

>>16
"yoba" means gimmick. a common name for useless stuff, like factorials, fibs and prime numbers.

Name: Anonymous 2011-04-25 1:33

>>19
yoba means game you can't afford.

Name: Anonymous 2011-04-25 1:41

>>20
Yep. I don't have enough stupidity for it.

Name: Anonymous 2011-04-25 5:01

>>16
Y.O.B.A. is an acronym for graphics-intensive games with primitive gameplay, terrible story and no atmosphere, that was spawned in videogames sections of many Russian imageboards.  It means ``Youth Oriented, Bydlo1 Approved''.  Then it crept into programming sections and is now used as a placeholder, much like foo/bar/baz.

But the more important part: ``in Lisp'' troll and finitist troll are the same person, and that person also trolls 0chan.ru.  While there are many Russian posters here, the said troll stands out with his particularly terrible English.

__
1 literally ``cattle'', a low-cultured no-thinking non-individualist.

Name: Anonymous 2011-04-25 6:38

>>22
You're lying, jew.

Name: Anonymous 2011-04-25 6:43

>>22
said troll stands out with his particularly terrible English.
Why've you capitalized word "English", retard?

Name: Anonymous 2011-04-25 6:48

>>22
finitist troll
And I'm not "finitist", you idiot!

Name: Anonymous 2011-04-25 7:18

>>24
Any reason why not?

Name: Anonymous 2011-04-25 7:38

>>26
Any reason why you believe in infinity, jew?

Name: Anonymous 2011-04-25 7:41

>>22
Thank you!
I've always thought they were the same person.

Name: Anonymous 2011-04-25 7:49

>>28
Hope now you'll use ad hominem against me even more often, making you look like a complete dolt.

Name: Anonymous 2011-04-25 7:50

>>29

Name: 2011-04-25 7:57

>>29
Hope now you'll use ∞ against me ∞, making ∞ ∞ like a complete ∞.

Name: Anonymous 2011-04-25 8:24

>>31
∞ MY ANUS

Name: Anonymous 2011-04-25 12:10

Name: Anonymous 2011-04-25 12:55

∞ OF PUSSY AND ASS

Name: Anonymous 2011-04-25 13:01

Name: Sageru Sensei 2011-04-25 14:22

>> 1
[o][u][i][b]ENTERPRISE QUALITY U MENA HASKAL[\b][\i][\u][\o]
( ≖‿≖)

Name: Anonymous 2011-04-25 14:23

>>1
[o][u][i][b]ENTERPRISE QUALITY U MENA HASKAL[\b][\i][\u][\o]
( ≖‿≖)

Name: >>1-san 2011-04-25 17:48

[\b][\i][\u][\o]
( ≖‿≖)
I MENA HASKAL

Name: Anonymous 2011-04-26 0:21


import Data.Array.ST
import Control.Monad.ST
import Control.Monad
 
getRange a = range `liftM` getBounds a
 
t arr = do
  h:t <- getRange arr
  f <- readArray arr h
  let
    swap x y = do
      a <- readArray arr x
      b <- readArray arr y
      writeArray arr x b
      writeArray arr y a
    chk cond k = do
      z <- readArray arr k
      return $ cond z
    go t = do
      l <- getElems arr
      a <- findT (chk(>f)) t
      case a of
        Nothing -> return $ last t
        Just (x:xs) -> do
          a <- findT (chk(<f)) xs
          case a of
            Nothing -> return $ x - 1
            Just (y:ys) -> do
              swap y x
              go xs
  a <- go t
  swap h a
 
findT f l@(x:xs) = do
  a <- f x
  case a of
    True -> return $ Just l
    False -> findT f xs
findT f [] = return Nothing 
 
mkArr :: [Int] -> ST s (STArray s Int Int)
mkArr arg = newListArray (1,length arg) arg
 
test = runST $ do
  a <- mkArr [433,65,435,12,67]
  t a
  getElems a

Name: Anonymous 2011-04-26 0:25

>>39
Compare to C#

class Program
{
    const int N = 20;
    static void Main()
    {
        Random rand = new Random();
        int[] a = new int[N];
        Console.WriteLine("initial array:");
        for (int i = 0; i < N; ++i)
        {
            a[i] = rand.Next(-99, 99);
            Console.Write("{0,4}", a[i]);
        }
        Console.WriteLine();
        int[] b = new int[N];
        int k = 0;
        for (int i = 1; i < N; ++i)
        {
            if (a[i] < a[0]) b[k++] = a[i];
        }
        b[k++] = a[0];
        for (int i = 1; i < N; ++i)
        {
            if (a[i] >= a[0]) b[k++] = a[i];
        }
        Console.WriteLine("transformed array:");
        for (int i = 0; i < N; ++i)
        {
            Console.Write("{0,4}", b[i]);
        }
        Console.WriteLine();
        Console.ReadLine();
    }
}

Name: Anonymous 2011-04-26 8:06

Name: Anonymous 2011-04-26 8:11

Name: Anonymous 2011-04-26 8:17

Name: Anonymous 2011-04-26 8:22

Name: Anonymous 2011-04-26 8:27

Name: Anonymous 2011-04-26 8:33

Name: Anonymous 2011-04-26 8:38

Name: Anonymous 2011-04-26 8:43

Name: Anonymous 2011-04-26 8:48

Name: Anonymous 2011-04-26 8:54

Name: Anonymous 2011-04-26 8:59

Name: Anonymous 2011-04-26 9:04

Name: Anonymous 2011-04-26 9:10

Name: Anonymous 2011-04-26 9:15

Name: Anonymous 2011-04-26 9:20

Name: Anonymous 2011-04-26 9:25

Name: Anonymous 2011-04-26 9:31

Name: Anonymous 2011-04-26 9:36

Name: Anonymous 2011-04-26 9:41

Name: Anonymous 2011-04-26 9:46

Name: Anonymous 2011-04-26 9:51

Name: Anonymous 2011-04-26 9:56

Name: Anonymous 2011-04-26 10:02

Name: Anonymous 2011-04-26 10:07

Name: Anonymous 2011-04-26 10:12

Name: Anonymous 2011-04-26 10:25

Name: Anonymous 2011-04-26 10:29

Name: Anonymous 2011-04-26 10:34

Name: Anonymous 2011-04-26 10:39

Name: Anonymous 2011-04-26 10:44

Name: Anonymous 2011-04-26 10:48

Name: Anonymous 2011-04-26 10:53

Name: Anonymous 2011-04-26 10:58

Name: Anonymous 2011-04-26 11:02

Name: Anonymous 2011-04-26 11:07

Name: Anonymous 2011-04-26 11:12

Name: Anonymous 2011-04-26 11:17

Name: Anonymous 2011-04-26 11:21

Name: Anonymous 2011-04-26 11:26

Name: Anonymous 2011-04-26 11:31

Name: Anonymous 2011-04-26 11:35

Name: Anonymous 2011-04-26 11:40

Name: Anonymous 2011-04-26 11:45

Name: Anonymous 2011-04-26 11:50

Name: Anonymous 2011-04-26 11:55

Name: Anonymous 2011-04-26 11:59

Name: Anonymous 2011-04-26 12:04

Name: Anonymous 2011-04-26 12:09

Name: Anonymous 2011-04-26 12:13

Name: Anonymous 2011-04-26 12:18

Name: Anonymous 2011-04-26 12:23

Name: Anonymous 2011-04-26 12:27

Name: Anonymous 2011-04-26 12:32

Name: Anonymous 2011-04-26 12:37

Name: Anonymous 2011-04-26 12:41

Name: Anonymous 2011-04-26 12:46

Name: Anonymous 2011-04-26 12:51

Name: Anonymous 2011-04-26 12:55

Name: Anonymous 2011-04-26 13:00

Name: Anonymous 2011-04-26 13:05

Name: Anonymous 2011-04-26 13:10

Name: Anonymous 2011-04-26 13:14

Name: Anonymous 2011-04-26 13:19

Name: Anonymous 2011-04-26 13:24

Name: Anonymous 2011-04-26 13:29

Name: Anonymous 2011-04-26 13:33

Name: Anonymous 2011-04-26 13:38

Name: Anonymous 2011-04-26 13:43

Name: Anonymous 2011-04-26 13:48

Name: Anonymous 2011-04-26 13:52

Name: Anonymous 2011-04-26 13:57

Name: Anonymous 2011-04-26 14:01

Name: Anonymous 2011-04-26 14:06

Name: Anonymous 2011-04-26 14:11

Name: Anonymous 2011-04-26 14:16

Name: Anonymous 2011-04-26 14:20

Name: Anonymous 2011-04-26 14:25

Name: Anonymous 2011-04-26 14:30

Name: Anonymous 2011-04-26 14:35

Name: Anonymous 2011-04-26 14:39

Name: Anonymous 2011-04-26 14:44

Name: Anonymous 2011-04-26 14:49

Name: Anonymous 2011-04-26 14:54

Name: Anonymous 2011-04-26 14:58

Name: Anonymous 2011-04-26 15:03

Name: Anonymous 2011-04-26 15:08

Name: Anonymous 2011-04-26 15:13

Name: Anonymous 2011-04-26 15:18

Name: Anonymous 2011-04-26 15:26

Name: Anonymous 2011-04-26 15:31

Name: Anonymous 2011-04-26 15:36

Name: Anonymous 2011-04-26 15:40

Name: Anonymous 2011-04-26 15:45

Name: Anonymous 2011-04-26 15:50

Name: Anonymous 2011-04-26 15:54

Name: Anonymous 2011-04-26 15:59

Name: Anonymous 2011-04-26 16:04

Name: Anonymous 2011-04-26 16:09

Name: Anonymous 2011-04-26 16:13

Name: Anonymous 2011-04-26 16:18

Name: Anonymous 2011-04-26 16:23

Name: Anonymous 2011-04-26 16:28

Name: Anonymous 2011-04-26 16:33

Name: Anonymous 2011-04-26 16:37

Name: Anonymous 2011-04-26 16:42

Name: Anonymous 2011-04-26 16:47

Name: Anonymous 2011-04-26 16:52

Name: Anonymous 2011-04-26 16:57

Name: Anonymous 2011-04-26 17:01

Name: Anonymous 2011-04-26 17:06

Name: Anonymous 2011-04-26 17:11

Name: Anonymous 2011-04-26 17:16

Name: Anonymous 2011-04-26 17:20

Name: Anonymous 2011-04-26 17:25

Name: Anonymous 2011-04-26 17:27

Name: Anonymous 2011-04-26 17:35

Name: Anonymous 2011-04-26 19:06

Name: Anonymous 2011-04-26 19:10

Name: Anonymous 2011-04-26 19:15

Name: Anonymous 2011-04-26 19:19

Name: Anonymous 2011-04-26 19:33

Name: Anonymous 2011-04-26 19:37

Name: Anonymous 2011-04-26 19:43

Name: Anonymous 2011-04-26 19:48

Name: Anonymous 2011-04-26 19:52

Name: Anonymous 2011-04-26 19:56

Name: Anonymous 2011-04-26 20:00

Name: Anonymous 2011-04-26 20:10

Name: Anonymous 2011-04-26 20:15

Name: Anonymous 2011-04-26 20:19

Name: Anonymous 2011-04-26 20:23

Name: Anonymous 2011-04-26 20:28

Name: Anonymous 2011-04-26 21:33

Name: Anonymous 2011-04-26 21:37

Name: Anonymous 2011-04-26 22:00

Name: Anonymous 2011-04-26 22:43

Name: Anonymous 2011-04-26 23:27

Name: Anonymous 2011-04-26 23:38

Name: Anonymous 2011-04-27 0:02

Name: Anonymous 2011-04-27 0:56

Name: Anonymous 2011-04-27 1:35

Name: Anonymous 2011-04-27 1:47

Name: Anonymous 2011-04-27 1:59

Name: Anonymous 2011-04-27 2:04

Name: Anonymous 2011-04-27 2:08

Name: Anonymous 2011-04-27 2:12

Name: Anonymous 2011-04-27 3:08

Name: Anonymous 2011-04-27 3:12

Name: Anonymous 2011-04-27 3:17

Name: Anonymous 2011-04-27 3:30

Name: Anonymous 2011-04-27 3:34

Name: Anonymous 2011-04-27 3:38

Name: Anonymous 2011-04-27 3:43


Don't change these.
Name: Email:
Entire Thread Thread List