View ngrams.hs
1 2 3 4 5 6 7 8 9 10
groupEvery :: Int -> [a] -> [[a]]
groupEvery n lst
| length lst < n = []
| otherwise = take n lst : groupEvery n (tail lst)
 
ngrams :: Int -> String -> [String]
ngrams n = concatMap (groupEvery n . fillWord '_') . words
where fillWord f w = f : (w ++ replicate (n - 1) f)
 
main :: IO ()
View gist:ae0ae922199468e43f4c
1 2 3 4 5 6 7 8 9 10
module Snok.Engine
( Initializable(..)
, Drawable(..)
, play ) where
 
import qualified Graphics.UI.GLFW as GLFW
import System.Exit (exitSuccess, exitFailure)
import System.IO (stderr, hPutStrLn, hFlush)
import Control.Monad (when, unless)
import Control.Concurrent.STM
View gist:d43507abfb86622c79a2
1 2 3 4 5 6 7 8 9 10
{-| Class that represents an object that can be updated
every x amount of time (where x is fixed). |-}
class Mutable t where
update :: t -> Engine t
updateRate :: UPS
 
{-| Class representing an object that changes when
an user performs input operations. |-}
class Reactive t where
react :: Input -> t -> Engine t
View model.pm
1 2 3 4 5 6 7 8 9 10
use strict;
use warnings;
use XML::LibXML;
 
package Model {
 
# Factory class method that
# builds a model from an XML node.
sub _from_node {
my $class = shift;
View rest.hs
1 2 3 4 5 6 7 8 9 10
{-# LANGUAGE TypeFamilies, FlexibleInstances #-}
 
module Main where
 
-- API
class Referenceable a where
type ReferenceType a :: *
expand :: ReferenceType a -> IO a
 
-- Post & posts example
View PuzzleGenerator.hs
1 2 3 4 5 6 7 8 9 10
module Main where
 
import Prelude hiding (id)
import Data.List (intersperse)
import System.Random
import Control.Applicative
 
type PieceId = String
type PieceContent = Char
View ExampleInput.txt
1 2 3 4
0 A VUOTO 1 2 VUOTO
1 B VUOTO VUOTO 3 0
2 C 0 3 VUOTO VUOTO
3 D 1 VUOTO VUOTO 2
View perms.hs
1 2 3 4 5 6 7 8 9 10
-- Original question can be found here:
-- http://www.reddit.com/r/haskell/comments/2lq8dt/produce_infinite_list_with_a_string/
 
permWithRep :: Int -> [a] -> [[a]]
permWithRep = replicateM
 
allSets :: String -> [[String]]
allSets str = map (flip permWithRep $ str) [0..]
 
main :: IO ()
View pangram.hs
1 2 3 4 5 6 7 8 9 10
import Data.Char (toLower)
 
isPangram :: String -> Bool
isPangram s =
let ls = map (toLower) s
in null . filter (not . (`elem` ls)) $ ['a'..'z']
 
main :: IO ()
main = do
s <- getLine
View at_least_two_equal_digits.hs
1 2 3 4 5 6 7 8 9 10
import Data.Map (Map)
import qualified Data.Map as Map
 
countDistinct :: Ord a => [a] -> Int
countDistinct = Map.size . foldr fn Map.empty
where fn e = Map.insertWith (+) e 1
 
validStrings :: [String]
validStrings =
filter ((`elem` [1..3]) . countDistinct) $ do
Something went wrong with that request. Please try again.