Webブラウザのブックマークのデータ構造を作ってみましょう.ブックマークのツリーには以下のノードがあります.
- ブックマーク
- フォルダ
ノードはそれぞれ以下の要素を持ちます.
- name
import Data.Char (toUpper, intToDigit) | |
import Data.List (concat, words, tails, isPrefixOf) | |
upperCase :: String -> String | |
upperCase = map toUpper | |
removeSpace :: String -> String | |
removeSpace = concat . words | |
cover :: Eq a => [a] -> [a] -> Bool |
data Bookmark = Bookmark { name :: String, url :: String } | | |
Folder { name :: String, children :: [Bookmark] } deriving (Show, Eq) | |
root = Folder "root" [(Bookmark "sample1" "http://example.com"), | |
(Bookmark "sample2" "http://example.com"), | |
(Bookmark "sample3" "http://example.com")] | |
emptyChildren = Folder "root" [] | |
recursibleFolder = Folder "root" [(Bookmark "sample1" "http://example.com"), | |
root] |
module Parupunte | |
( (+) | |
, (*) | |
) where | |
import qualified Prelude as Pre | |
(+) a b = b Pre.* a | |
(*) a b = b Pre.+ a |
-- すごいHaskell読書会 in 大阪 #3 | |
-- 練習問題 | |
-- 問題1 | |
-- 次のリスト内包を **map** と **filter** で書き直してみましょう | |
-- [ x ^ 2 | x <- [1..5], odd x] | |
q1 = map (^2) $ filter odd [1..5] | |
-- 問題2 |
-- ex1 | |
-- my null | |
null' xs = xs == [] | |
-- my sum | |
sum' xs = if null' xs then 0 else head xs + sum' (tail xs) | |
-- my product | |
product' xs = if null' xs then 1 else head xs * product' (tail xs) |
- (void)sizeToFitWithAnchorPoint:(AnchorPoint)anchorPoint | |
{ | |
CGRect srcFrame = self.frame; | |
[self sizeToFit]; | |
CGRect dstFrame = self.frame; | |
CGPoint p = dstFrame.origin; | |
switch (anchorPoint) { | |
case AnchorPointRightTop: | |
p = CGPointMake( | |
CGRectGetMaxX(srcFrame) - dstFrame.size.width, |
final class Person { | |
var name: String | |
lazy var greeting: ImplicitlyUnwrappedOptional<String> = { | |
return "Hello, \(self.name)" | |
}() | |
init(_ name: String) { | |
self.name = name | |
} | |
} | |
var p = Person("Steve") |
enum N { | |
case Zero | |
indirect case Succ(N) | |
init(_ n: UInt) { | |
switch n { | |
case 0: self = .Zero | |
default: self = .Succ(N(n - 1)) | |
} | |
} |
import Foundation | |
public class JSON: Printable { | |
private let object: JSONObject | |
init(_ object: AnyObject?) { | |
self.object = JSONObject.parse(object) | |
} | |
private init(_ object: JSONObject) { | |
self.object = object | |
} |