n3paste.de

::

a haskell happstack pastebin

  • New paste
  • View pastes

  • Login

  • About
  • Most recent pastes (filtered)

    Filter pastes (help):

    20:49 - Fri 2017.02.24

    Haskell

    Paste: /y2/Show related

    No description.

    module Main where
    
    import Graphics.X11
    import Control.Concurrent (threadDelay)
    
    main :: IO ()
    main = do
      display <- openDisplay ""
      let defScr = defaultScreen display
      rw <- rootWindow display defScr
      xwin <- createSimpleWindow display rw
          0 0 400 200 1
          (whitePixel display defScr)
          (blackPixel display defScr)
      setTextProperty display xwin "huehuehue u mett?" wM_NAME
      gc <- createGC display xwin
      setForeground display gc $ whitePixel display defScr
      setBackground display gc $ blackPixel display defScr
      setFillStyle display gc fillSolid
      setLineAttributes display gc 2 lineSolid capRound joinRound
    

    13:58 - Wed 2017.02.22

    Haskell

    Paste: /mH0R/Show related

    belsts monky.hs

    {-# LANGUAGE OverloadedStrings #-}
    
    import Monky
    import Monky.Modules
    import Monky.Examples.Sound.Alsa
    import Monky.Examples.CPU
    import Monky.Examples.Memory
    import Monky.Examples.Network
    import Monky.Examples.Time
    import Monky.Examples.Battery
    import Monky.Examples.Wifi
    import Monky.Examples.Disk
    import Monky.Examples.MPD
    import Monky.Examples.Modify
    import Monky.Examples.IBus
    import Monky.Outputs.Dzen2
    import Data.Monoid ((<>))
    import Data.List (isPrefixOf)
    import qualified Data.Text as T
    
    

    21:11 - Fri 2017.02.10

    Haskell

    Paste: /0hQL/Show related

    No description.

    module Main where
    
    main = do
      doStuff $ Left "shitty error"
      doStuff $ Right "everything good"
    
    doStuff :: Show a, Show b => Either a b -> IO ()
    doStuff (Left e) = print e
    doStuff (Right val) = print val
    

    19:33 - Thu 2016.09.22

    Haskell

    Paste: /fG8S/Show related

    #whatthehaskell

    -- Let's take a regular function
    
    acceptUpload :: UpMonad m => FileDescription -> FilePath -> m Response
    acceptUpload fd tmp = return OkResponse
    
    -- and turn around the arguments of the type to:
    
    acceptUpload :: FileDescription -> FilePath -> UpMonad m => m Response
    acceptUpload fd tmp = return OkResponse
    
    -- Such that it is no longer a valid Haskell function. GHC will complain, but
    -- at the same time offers the solution to the dilemma:
    
    {-
    
    λ nils@aslaug. cabal build
    Building file-upload-0.1.0.0...
    Preprocessing executable 'file-upload-server' for file-upload-0.1.0.0...
    [14 of 15] Compiling Page.Upload      ( src/Page/Upload.hs, dist/build/file-upload-server/file-upload-server-tmp/Page/Upload.o )
    
    

    12:20 - Fri 2016.09.02

    Haskell

    Paste: /Qhng/Show related

    yay monadz

    module Main (main) where
    
    import           Debug.Trace (trace)
    
    with :: (Num a) => Maybe a -> Maybe a -> Maybe a -> a
    with x y z = case ( do
        a <- trace "Evaluated x" x
        b <- trace "Evaluated y" y
        c <- trace "Evaluated z" z
        return $ a + b + c
      ) of
      (Just p) -> p
      Nothing  -> 0
    
    
    main = do
      putStrLn "All Just"
      print $ with (Just 1) (Just 2) (Just 3)
      putStrLn "Final Nothing"
      print $ with (Just 1) (Just 2) Nothing
    

    12:07 - Tue 2016.01.05

    Haskell

    Paste: /nz/Show related

    No description.

    import System.IO
    import Control.Exception
    import Control.Concurrent(threadDelay)
    import System.Posix.Process(getProcessID)
    import System.Process(callCommand)
    
    h :: String -> IOException -> IO ()
    h s _ = putStrLn $ "Oops: " ++ s
    
    flunkit :: IO ()
    flunkit = handle (h "a") $ do
      a <- openFile "a.txt" ReadMode
      hPutStrLn a "Can't write to something in ReadMode"
    
    checkit :: IO ()
    checkit
      = handle (h "b")
      . withFile "b.txt" ReadMode
      $ \b -> hPutStrLn b "Can't write to something in ReadMode"
    
    

    15:54 - Tue 2015.12.08

    Haskell

    Paste: /fRIV/Show related

    No description.

    -- meh.hs
    import Data.Char (ord,chr)
    import System.Environment(getArgs)
    
    main = putStrLn . map (chr . (\c -> if c < 32 then c else c-32) . ord) . unwords =<< getArgs
    
    -- ord.hs
    main = mapM_ print =<< getContents
    
    {- $ ./meh 'heisann, montebello!' | ./ord
     - 'H'
     - 'E'
     - 'I'
     - 'S'
     - 'A'
     - 'N'
     - 'N'
     - '\f'
     - '\NUL'
     - 'M'
    

    22:54 - Sat 2015.03.07

    Haskell

    Paste: /hwI/Show related

    No description.

    løk = undefined
    

    11:56 - Thu 2015.02.26

    Haskell

    Paste: /rZA/Show related

    No description.

    import Control.Concurrent(threadDelay)
    import System.Random(randomRIO)
    import Control.Monad(forever)
    
    løk = putStr "løk " >> randomRIO (80000,800000) >>= threadDelay
    
    main = forever løk
    

    15:47 - Thu 2014.11.13

    Haskell

    Paste: /RWGQ/Show related

    No description.

    {-# LANGUAGE OverloadedStrings #-}
    
    import Control.Arrow
    import Control.Monad.Writer
    import Data.Text
    import Data.Time
    
    import System.IO
    
    import Text.Blaze.Html5 as H
    import Text.Blaze.Html.Renderer.Pretty
    
    (<!>)
      :: Monad m
      => (Markup -> Markup)
      -> WriterT Markup m a
      -> WriterT Markup m a
    h <!> m = mapWriterT (liftM $ second h) m
    
    -- same infix rules as ($)
    

    17:20 - Thu 2014.11.06

    Haskell

    Paste: /xixU/Show related

    No description.

    import System.IO
    import Control.Monad
    import Data.List ( minimumBy )
    import Data.Ord  ( comparing )
    
    toInts :: [String] -> [Int]
    toInts [] = []
    toInts (x:xs) = read x : toInts xs
    
    main :: IO ()
    main = do
        hSetBuffering stdout NoBuffering -- DO NOT REMOVE
    
        -- Auto-generated code below aims at helping you parse
        -- the standard input according to the problem statement.
    
        input_line <- getLine
        let n = read input_line :: Int -- the number of temperatures to analyse
    
        if n == 0
    

    17:16 - Thu 2014.11.06

    Haskell

    Paste: /yxz/Show related

    No description.

    import System.IO
    import Control.Monad
    import Data.List  ( elemIndex )
    import Data.Maybe ( fromJust  )
    
    main :: IO ()
    main = do
        hSetBuffering stdout NoBuffering -- DO NOT REMOVE
    
        -- Auto-generated code below aims at helping you parse
        -- the standard input according to the problem statement.
    
        loop
    
    loop :: IO ()
    loop = do
        input_line <- getLine
        let input = words input_line
        let sx = read (input!!0) :: Int
        let sy = read (input!!1) :: Int
    

    16:52 - Thu 2014.11.06

    Haskell

    Paste: /rKRd/Show related

    No description.

    import System.IO
    import Control.Monad
    
    action :: Int -> Int -> Int -> Int -> Int -> IO ()
    action r g l x s
      | x == (r - 1) = putStrLn "JUMP"
      | x > r = putStrLn "SLOW"
      | x < r && s <= g = putStrLn "SPEED"
      | x < r && x + s > g + l && (s - 1) > g = putStrLn "SLOW"
      | x < r && g + s > l && (s - 1) > g = putStrLn "SLOW"
      | x < r && s > g = putStrLn "WAIT"
    
    main :: IO ()
    main = do
        hSetBuffering stdout NoBuffering -- DO NOT REMOVE
    
        -- Auto-generated code below aims at helping you parse
        -- the standard input according to the problem statement.
    
        input_line <- getLine
    

    23:17 - Sun 2014.09.28

    Haskell

    Paste: /ghg7/Show related

    some haskell code

    this :: a -> ref a
    

    21:20 - Thu 2014.08.28

    Haskell

    Paste: /Ufkj/Show related

    bindrop journal

    {-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving,
      TemplateHaskell, TypeFamilies, OverloadedStrings #-}
    
    module Bindrop.State.Journal where
    
    import Control.Lens.TH      ( makeLenses )
    import Data.Acid
    import Data.Data            ( Data, Typeable )
    import Data.IxSet           ( Indexable(..), (@=), (@<), getOne
                                , inferIxSet, noCalcs, toDescList)
    import qualified Data.IxSet as IxSet
    import Data.SafeCopy        ( base, deriveSafeCopy )
    import Data.Time            ( UTCTime(..) )
    
    data Journal = Journal { _acount  :: Int --account count
                           , _ucount  :: Int --upload count
                           , _dcount  :: Int --download count
                           } deriving (Eq, Ord, Show, Data, Typeable)
    
    $(makeLenses ''Journal)
    

    17:07 - Sun 2014.08.24

    Haskell

    Paste: /XmH/Show related

    No description.

    nils :: [(a, Maybe b)] -> [(a,b)]
    nils [] = []
    nils ((_,Nothing):xs) = nils xs
    nils ((a,Just b):xs) = (a,b) : nils xs
    

    17:39 - Sat 2014.08.02

    Haskell

    Paste: /OB/Show related

    No description.

    {-# LANGUAGE KindSignatures #-}
    {-# LANGUAGE DataKinds #-}
    {-# LANGUAGE MultiParamTypeClasses #-}
    {-# LANGUAGE TypeFamilies #-}
    {-# LANGUAGE FlexibleInstances #-}
    {-# LANGUAGE FlexibleContexts #-}
    {-# LANGUAGE UndecidableInstances #-}
    
    class Print' (flag :: Bool) a where
      print' :: a -> IO ()
    
    class Print a where
      print :: a -> IO ()
    
    type family ShowWorks a where
      ShowWorks Int = True
      ShowWorks a   = False
    
    instance Show a => Print' True a where
      print' = putStrLn . show
    

    22:46 - Fri 2014.08.01

    Haskell

    Paste: /Dr0/Show related

    No description.

    import Control.Lens
    import System.FilePath.Lens
    import System.Directory
    
    import Control.Applicative
    import System.Random
    
    randomStringIO :: Int -> IO String
    randomStringIO len = randomString len <$> newStdGen
    
    randomString :: RandomGen g => Int -> g -> String
    randomString len gen =
      let alphanum = ['0'..'9'] ++ ['a'..'z'] ++ ['A'..'Z']
          indxs    = take len $ randomRs (0, length alphanum - 1) gen
       in map (alphanum !!) indxs
    
    moveToRandomFile
      :: FilePath         -- ^ file directory
      -> Int              -- ^ length of filename
      -> FilePath         -- ^ file
    

    19:31 - Fri 2014.08.01

    Haskell

    Paste: /W8Eh/Show related

    No description.

    import Control.Applicative
    import System.Random
    
    randomStringIO :: Int -> IO String
    randomStringIO len = randomString len <$> newStdGen
    
    randomString :: RandomGen g => Int -> g -> String
    randomString len gen =
      let alphanum = ['0'..'9'] ++ ['a'..'z'] ++ ['A'..'Z']
          indxs    = take len $ randomRs (0, length alphanum - 1) gen
       in map (alphanum !!) indxs
    

    14:49 - Wed 2014.07.30

    Haskell

    Paste: /9BB/Show related

    No description.

    {-# LANGUAGE DeriveDataTypeable #-}
    {-# LANGUAGE TemplateHaskell #-}
    
    import Data.Typeable
    import Data.Time.Clock
    import Data.SafeCopy
    
    data Test = Test
      { testTime :: UTCTime
      }
      deriving (Typeable)
    
    deriveSafeCopy 1 'base ''Test