This file contains hidden or 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
middleList xs = | |
let n = length xs | |
fnum = 2*((n `div` 2) `div` 2) | |
in take (if odd n then 1 else 2) $ drop fnum xs |
This file contains hidden or 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
middleList xs = | |
let n = length xs | |
fnum = 2*(n `div` 4) | |
in take (if odd n then 1 else 2) $ drop fnum xs |
This file contains hidden or 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
middleList xs@(_:_:_:_) = | |
let n = length xs | |
en = if n < 5 then 1 else 2 * (n `div` 4) | |
in take (if odd n then 1 else 2) $ drop en xs | |
middleList _ = error "List is too short." |
This file contains hidden or 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
module Main where | |
import Control.Monad | |
import Data.List | |
import Data.Char | |
import System.IO | |
import Text.Regex.Posix | |
import Text.Regex | |
getSecondWord :: String -> String |
This file contains hidden or 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
middleList xs@[x] = xs | |
middleList xs@[x,y] = xs | |
middleList xs = | |
let n = length xs | |
en = if n < 5 then 1 else 2 * (n `div` 4) | |
in take (if odd n then 1 else 2) $ drop en xs |
This file contains hidden or 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
middleList xs@[x] = xs | |
middleList xs@[x,y] = xs | |
middleList xs = | |
let n = length xs | |
en = if n < 5 then 1 else 2 * (n `div` 4) | |
in take (if odd n then 1 else 2) $ drop en xs |
This file contains hidden or 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
middleList xs@(_:_:_:_) = | |
let n = length xs | |
en = if n < 5 then 1 else 2 * (n `div` 4) | |
in take (if odd n then 1 else 2) $ drop en xs | |
middleList xs = xs |
This file contains hidden or 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
GHCi, version 6.10.3: http://www.haskell.org/ghc/ :? for help | |
Loading package ghc-prim ... linking ... done. | |
Loading package integer ... linking ... done. | |
Loading package base ... linking ... done. | |
Prelude> :load "/home/rayne/hsprojs/learn/Test.hs" | |
[1 of 1] Compiling Main ( /home/rayne/hsprojs/learn/Test.hs, interpreted ) | |
Ok, modules loaded: Main. | |
*Main> :load "/home/rayne/hsprojs/learn/Test.hs" | |
[1 of 1] Compiling Main ( /home/rayne/hsprojs/learn/Test.hs, interpreted ) |
This file contains hidden or 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
middleList xs@(_:_:_:_) = take (if odd n then 1 else 2) $ drop en xs | |
where n = length xs | |
en = if n < 5 then 1 else 2 * (n `div` 4) | |
middleList xs = xs |
This file contains hidden or 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
module MyMaybe where | |
import Data.List | |
data MyMaybe a = MyJust a | |
| MyNothing | |
deriving (Show) | |
myMaybe :: b -> (a -> b) -> MyMaybe a -> b | |
myMaybe dval f mmval = case mmval of |