open-sorcerers / madlib

Madlib: a compile-to-JS language written in Haskell, designed to make writing code a delight
https://github.com/madlib-lang/madlib
BSD 3-Clause "New" or "Revised" License
3 stars 0 forks source link

Type classes #38

Closed aboeglin closed 3 years ago

aboeglin commented 3 years ago

I’m still not sure if it’s a wanted feature but it would definitely allow people to write dryer code in madlib.

class Show a {
  show :: a -> String
}

instance Show Number {
  show = (num) => #- num.toString() -#
}

instance Show a => Show List a {
  show = (xs) => pipe(
    map(show),
    intercalate(“,”),
    wrap(“[“, “]”)
  )(xs)
}

Show Number would most likely be implemented by prelude and need the host support to make the conversion happen.

aboeglin commented 3 years ago

Closed by #42