Skip navigation.
Home

RNDr. Petr Pudlák, PhD.

Vítejte na mé domácí stránce.

Prosím zvolte položku v menu.

RNDr. Petr Pudlák, PhD.

Welcome to my homepage.

Please select a section from the menu.

Scala dependency injection

Recently I've discovered Scala, and being a functional languages fan I enjoyed many great Scala's features. I decided to use it in our projects and one of the things I wanted to learn is how to do dependency injection in some elegant way.

After searching for a while I stumbled upon [url=http://jonasboner.com/]Jonas Bonér's[/url] great article [url=http://jonasboner.com/2008/10/06/real-world-scala-dependency-injection-di.html]Real-World Scala: Dependency Injection (DI)[/url]. I learned a lot about Scala from the article, as well as about dependency injection. But I wasn't comfortable with one thing in his approach: The dependencies of a component are fixed in such a way that it's not possible to have two different components providing the same service, but each depending on different sub-components. (Or at least I wasn't able to figure it out.). For example, let's say that I have a service that returns a list of users and I want to implement it by two interchangeable components: one that reads users from a database and another that reads users from a file. So the former should depend on a database provider subcomponent, while the other one on a subcomponent providing access to a file-system. However, it's not very difficult to refine the idea a bit further to gain (IMHO) even more flexible architecture.

Memoization, monads (code)

module MemoFix where
{-
This is my exercise program for memoizing values of a generic recursively
defined function. My aim was to make the actual function definition as clear
as possible.
-}

import IO
import Maybe
import Control.Monad.State
import Control.Monad.Fix
import Control.Monad.Identity
import Data.Array
import Data.Map (Map)
import qualified Data.Map as Map
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap

{- A State that Memos key::a / value::b pairs.

Utlity class for removing diacritics.

import java.util.*;

/**
* A utility class that removes diacritics from characters. For example, czech
* příliš žluťoučký kůň úplěl ďábelské ódy becomes prilis zlutoucky
* kun upel dabelske ody.
* Data extracted from UnicodeData.txt.

Example how to construct a MHT (AKA MHTML) file in Java using JavaMail API

[blockcode language="java5"] import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; import java.io.*; import java.util.*; /** * Example how to construct a MHT (AKA MHTML) file in Java using JavaMail API. Creates a * simple HTML page (from a String) with an image, which * is pulled from a file. * * Requires mail.jar in the classpath (and also Java * Activation Framework if JDK version is less than 1.6). */
Syndicate content