This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-17
Channels
- # beginners (42)
- # cider (1)
- # cljs-dev (20)
- # clojure (73)
- # clojure-italy (8)
- # clojure-nl (53)
- # clojure-spec (11)
- # clojure-uk (88)
- # clojurescript (170)
- # clojutre (6)
- # core-async (26)
- # css (2)
- # cursive (13)
- # data-science (10)
- # datomic (15)
- # editors (3)
- # figwheel (28)
- # figwheel-main (67)
- # fulcro (57)
- # graphql (2)
- # immutant (2)
- # jobs (1)
- # jvm (4)
- # lein-figwheel (3)
- # leiningen (1)
- # off-topic (5)
- # pedestal (28)
- # re-frame (86)
- # reagent (18)
- # reitit (8)
- # ring (3)
- # ring-swagger (2)
- # shadow-cljs (78)
- # spacemacs (10)
- # specter (12)
- # tools-deps (32)
- # vim (3)
it’s kind of like storing something as Object in Java and then casting it back right when you need it to be of some type, but with the guarantee that you can never unsafely cast it to something it isn’t
the haskellers very good at inventing complicating stuff to limit themselves, and then inventing even more complicated stuff to overcome these limitations
The first time is saw http://hackage.haskell.org/package/HList i though it was a joke
@chris.blom that’s always the case in Haskell 😛
@chrisblom that’s always the case in Haskell (hey, I mentioned the wrong chrisblom)
@lmergen the point is that you will never have a runtime exception as a result of casting to the wrong type
but, but... then it's just the same like casting an Object
to a StringOrInt, and wrapping the exception in a Maybe ?
but maybe this code isn’t the best example, I wrote this only when I discovered that you could do this, not when I properly understood this topic 🙂
fromDynamic
returns a Nothing
or a Just a
of the type a
you wanted. You also have unsafeCoerce
in Haskell, this won’t get you an exception, but just returns bogus when applied wrongly.
Prelude Unsafe.Coerce> data Foo = A | B
Prelude Unsafe.Coerce> unsafeCoerce A :: Int
283479243147
but as far as i can see, it's mainly a way to wrap some arbitrary data in a Dynamic, and write your code that uses it with static guarantees