This will be a short and quick walk through on how to make REST API calls using AngularJS. We shall use ngResource to aid us. Loading ngResource If we want to use the ngResource module, we have to make sure it’s being loaded separately along with angular. We need to have something like – <script src="/static/js/angular.min.js" type="text/javascript"></script> <script src="/static/js/angular-resour
selectList is the most commonly used, so we will cover it specifically. Understanding the others should be trivial after that. selectList takes two arguments: a list of Filters, and a list of SelectOpts. The former is what limits your results based on characteristics; it allows for equals, less than, is member of, and such. SelectOpts provides for three different features: sorting, limiting output
Yesod で使われている Database.Persist ですが、どうも型シグニチャとかごちゃごちゃしててわかりにくいので、型を簡略化して説明を加えてみました。 参考: persistent-1.1.3.2 はじめに 型シグニチャは簡略化しています。haddock との対応は 値 → val キー → Key val ユニークキー → Unique val フィルタ → [Filter val] オプション → [SelectOpt val] 更新内容 → [Update val] といった感じです。 また、値とエンティティの違いですが、値はデータベースと関係なく存在するデータとすると、エンティティはデータベース上のレコードに対応し、キーの情報を持っています。 型シグニチャ中の m は、その関数が使えるモナドみたいなもんです…(うまく説明できない)。Scaffold された Yesod
Prelude には,const :: a -> b -> a という関数が定義されています.a -> b -> a という型は a -> (b -> a) のことなので,この関数を引数に適用すると,b -> a という型の関数になります.できあがった関数はどのような値 v :: b に適用しても,この関数を作るときに適用した引数を返します. ghci> :type const const :: a -> b -> a ghci> let k1 = const 1 ghci> k1 "Hoge" 1 ghci> k1 False 1 ghci> k1 undefined 1 ghci> let kHuga = const "Huga" ghci> kHuga "Hoge" "Huga" ghci> kHuga 2 "Huga" ghci> kHuga undefined "Huga"さて「
Prelude に const という関数がある。型は const :: a -> b -> a 簡単に言うと、引数を2つとって1つ目の引数をそのまま返す関数。 Prelude> const 1 2 1これと id を組み合わせてみると、引数を2つとって2つ目をそのまま返すようになる。 const id :: a -> b -> b Prelude> const id 1 2 2これは const id x = id となるから。 このように const に関数を与えると便利に使える場合がある。例えば myLast = foldr1 (const id) でリストの最後の要素を求めることができたり myLength = foldr (const (+1)) 0 でリストの長さが求められる。
localDatetimeField :: Field App App UTCTime localDatetimeField = Field { fieldParse = \rawVals fVals -> case rawVals of [dayF, timeF] -> runErrorT $ do tz <- liftIO getCurrentTimeZone mDay <- ErrorT $ fieldParse dayField [dayF] fVals mTime <- ErrorT $ fieldParse timeField [timeF] fVals return $ localTimeToUTC tz <$> (LocalTime <$> mDay <*> mTime) _ -> return $ Left . SomeMessage $ MsgInvalidDateti
Lately at work, I’ve been fortunate enough to work on a JSON API which I was given the freedom to write in Yesod. I was a bit hesitant at first since my only Yesod experience has been richer html-based sites and I wasn’t sure what support (if any) there was for strictly JSON APIs. Rails has a number of conveniences for writing concise controllers and standing up APIs quickly – I was afraid Yesod m
Haskellのorphan instanceが何者なのか、その意味するところをちゃんと理解してなかったので調べてみた。 orphan instancesとは何? 型クラスの定義ともデータ型の定義とも異なるモジュールで定義されたインスタンス宣言のこと 例: T.hsで定義されたデータ型Tについて、モジュールM.hsでinstance Show Tとインスタンス宣言されていたら、それはorphan instance。 このインスタンス宣言は、型クラスShowともデータ型Tとも異なるモジュールで宣言されているから。 orphan instancesはいいもん?わるもん? ケースバイケース 前提: Haskell 98では重複した*1インスタンス宣言を扱えない。 利点: ケースによってインスタンス宣言を差し替えられるように、複数のインスタンスを定義したい場合は、別モジュールに定義する(つまりor
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く