This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
intervals :: (Eq a, Enum a) => [a] -> [(a, Maybe a)] | |
intervals [] = [] | |
intervals (x:[]) = [(x, Nothing)] | |
intervals (x:xs) = (x, lastSuccessor x x xs) : intervals (dropSuccessors x xs) | |
where | |
lastSuccessor :: (Eq a, Enum a) => a -> a -> [a] -> Maybe a | |
lastSuccessor l x [] | |
| l == x = Nothing | |
| otherwise = Just x | |
lastSuccessor l x (y:ys) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
# requires Python 2.5 | |
assert sys.version_info[1] >= 5, "Requires Python Coroutines. See PEP 0342" | |
def pushbackiter(iterator): | |
"""converts 'iterator' into a coroutine, with limited pushback | |
>>> it = pushbackiter([1,2,3,4,5]) | |
>>> it.next() | |
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> import Control.Exception ( handle, IOException ) | |
here is a specialize handle which deals with IOExceptions | |
> handleIO :: (IOException -> IO a) -> IO a -> IO a | |
> handleIO = handle | |
Without this added signature you will get type-check errors like this: | |
Ambiguous type variable `e' in the constraint: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> import Distribution.Simple | |
This is an example Setup.hs for a haskell program making use of HaskellDB. | |
> import System.Directory ( removeFile, removeDirectoryRecursive ) | |
HaskellDB needs to have the structure of all database tables laid out as data. | |
> import Database.HaskellDB | |
> import Database.HaskellDB.DBSpec |
NewerOlder