Idris eager evaluation

We say Idris has strict evaluation, but this is for its run-time semantics. Being a fully dependently typed language, Idris has two phases where it evaluates things, compile-time and run-time. At compile-time it will only evaluate things which it knows to be total (i.e. terminating and covering all possible inputs) in order to keep type … Read more

Return first non-null value

String s = Stream.<Supplier<String>>of(this::first, this::second /*, … */) .map(Supplier::get) .filter(Objects::nonNull) .findFirst() .orElseGet(this::defaultOne); It stops on the first non-null value or else sets the value which is returned from defaultOne. As long as you stay sequential, you are safe. Of course this requires Java 8 or later. The reason why it stops on the first occurrence … Read more

Python class member lazy initialization

You could use a @property on the metaclass instead: class MyMetaClass(type): @property def my_data(cls): if getattr(cls, ‘_MY_DATA’, None) is None: my_data = … # costly database call cls._MY_DATA = my_data return cls._MY_DATA class MyClass(metaclass=MyMetaClass): # … This makes my_data an attribute on the class, so the expensive database call is postponed until you try to … Read more

How do laziness and parallelism coexist in Haskell?

Yes, GHC’s RTS uses thunks to implement non-strict evaluation, and they use mutation under the hood, so they require some synchronisation. However, this is simplified due to the fact that most heap objects are immutable and functions are referentially transparent. In a multithreaded program, evaluation of a thunk proceeds as follows: The thunk is atomically† … Read more

What is the relationship between unboxed types and strictness?

Unboxed vs Boxed Data To support parametric polymorphism and laziness, by default Haskell data types are represented uniformly as a pointer to a closure on the heap, with a structure like this: (source: haskell.org) These are “boxed” values. An unboxed object is represented by the value itself directly, without any indirection or closure. Int is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)