Aug. 11th, 2013

yorool_gui: (лысый)
Оказывается в Хаскеле давным давно есть полноценный полиморфизм как в объектных языках. Стал разбираться с ixset и обнаружил. А я-то мучился, как без виртуальных функций жить:

{-# LANGUAGE ExistentialQuantification, StandaloneDeriving #-}
module Main where
data Polymorph = forall b . (Show b) => Polymorph b
deriving instance Show Polymorph
main = do
  let polymorph = [Polymorph "String", Polymorph (1::Int), Polymorph (0.5::Double)]
  putStrLn $ show polymorph

Profile

yorool_gui: (Default)
Michael Ilyin

April 2017

S M T W T F S
      1
2 345678
910 1112131415
16171819202122
23242526272829
30      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 24th, 2025 05:35 pm
Powered by Dreamwidth Studios