Skip to content

Instantly share code, notes, and snippets.

@voidlizard
Created October 11, 2014 18:22
Show Gist options
  • Save voidlizard/3a9df42ddf1fb1e28891 to your computer and use it in GitHub Desktop.
Save voidlizard/3a9df42ddf1fb1e28891 to your computer and use it in GitHub Desktop.
{-# Language MultiParamTypeClasses
, TypeFamilies
, FlexibleContexts
, FlexibleInstances #-}
module Main where
import qualified Data.List as L
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as U
class WithDistance a b where
distance_ :: a b -> a b -> b
class ( Num (Elem c)
, Ord (TLabel c)
, WithDistance (TVect c) (Elem c)
)
=> DataSet c where
type Elem c :: *
type TLabel c :: *
type TVect c :: * -> *
data TObservation c :: *
observations :: c -> [TObservation c]
measurements :: TObservation c -> [Elem c]
label :: TObservation c -> TLabel c
distance :: TVect c (Elem c) -> TVect c (Elem c) -> Elem c
distance xs ys = distance_ xs ys
instance Num a => WithDistance [] a where
distance_ xs ys = L.sum (L.zipWith (+) xs ys)
instance Num a => WithDistance V.Vector a where
distance_ xs ys = V.sum (V.zipWith (+) xs ys)
instance WithDistance U.Vector Float where
distance_ xs ys = U.sum (U.zipWith (+) xs ys)
instance DataSet () where
type Elem () = Float
type TLabel () = Int
data TObservation () = TObservationUnit [Float]
type TVect () = V.Vector
observations () = replicate 10 (TObservationUnit [0,0,0,0])
measurements (TObservationUnit xs) = xs
label (TObservationUnit _) = 666
kMeans :: DataSet c => c -> [TObservation c]
kMeans s = undefined
where
wtf1 = L.foldl wtf2 0 (observations s)
wtf2 acc xs = acc + L.sum (measurements xs)
main = do
putStrLn "jopa"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment