Skip to content

Instantly share code, notes, and snippets.

@hodzanassredin
Created December 1, 2011 10:59
Show Gist options
  • Save hodzanassredin/1415832 to your computer and use it in GitHub Desktop.
Save hodzanassredin/1415832 to your computer and use it in GitHub Desktop.
simple type level predicates in haskell
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, UndecidableInstances #-}
module Prolog (Petja, Vasja, Serg, Father) where
data Petja = Petja
data Vasja = Vasja
data Serg = Serg
class Father a b where
isFather :: a -> b -> ()
isFather x y = ()
instance Father Vasja Petja
instance Father Petja Serg
class Son a b where
isSon :: a -> b -> ()
isSon x y = ()
instance (Father b a) => Son a b
class GrandFather a b c where
isGrandFather :: a -> c -> ()
isGrandFather x y = ()
instance (Father a b, Father b c) => GrandFather a b c
@hodzanassredin
Copy link
Author

сенкс

@hodzanassredin
Copy link
Author

Хм а получается что у отца может быть только один сын?

@hodzanassredin
Copy link
Author

Интересно надо будет поэкспериментировать.

@laughedelic
Copy link

Вроде как нет. Я создавал нескольких детей и всё было ок. Даже сделал класс Brothers ")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment