Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jyothsnasrinivas committed Nov 14, 2017
0 parents commit 09edff1
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Revision history for eta-scala-interop

## 0.1.0.0 -- YYYY-mm-dd

* First version. Released on an unsuspecting world.
30 changes: 30 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright (c) 2017, Jyothsna Srinivas

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Jyothsna Srinivas nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 2 additions & 0 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
20 changes: 20 additions & 0 deletions eta-scala-interop.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: eta-scala-interop
version: 0.1.0.0
synopsis: Utilities for interoperating with Scala.
description: Utilities for interoperating with Scala.
license: BSD3
license-file: LICENSE
author: Rahul Muttineni, Jyothsna Patnam
maintainer: jyothsnasrinivas17@gmail.com
copyright: Copyright (c) Rahul Muttineni 2017
(c) Jyothsna Patnam 2017
category: Interop
build-type: Simple
extra-source-files: ChangeLog.md
cabal-version: >=1.10

library
exposed-modules: Interop.Scala
build-depends: base >=4.8 && <4.9
hs-source-dirs: src
default-language: Haskell2010
100 changes: 100 additions & 0 deletions src/Interop/Scala.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{-# LANGUAGE NoImplicitPrelude, MagicHash, MultiParamTypeClasses,
FlexibleContexts, FlexibleInstances, TypeOperators #-}
-----------------------------------------------------------------------------
-- |
-- Module : Scala
-- Copyright : (c) Rahul Muttineni 2017
--
-- License : BSD-style (see the file libraries/base/LICENSE)
--
-- Maintainer : rahulmutt@gmail.com
-- Stability : provisional
-- Portability : portable
--
-- Helpers for dealing with Scala APIs.
--
-- TODO: Move to a separate scala package later
--
-----------------------------------------------------------------------------

module Interop.Scala
(Tuple2(..), Tuple3(..), Tuple4(..), Tuple5(..))
where

import GHC.Base
import GHC.Show
import Java

data Tuple2 a b = Tuple2 (@scala.Tuple2 a b)
deriving (Class, Show, Eq)

foreign import java unsafe "@new" toTuple2
:: (a <: Object, b <: Object) => a -> b -> Tuple2 a b

foreign import java unsafe "_1" tup2_1 :: (a <: Object) => Tuple2 a b -> a

foreign import java unsafe "_2" tup2_2 :: (b <: Object) => Tuple2 a b -> b

instance (Extends a Object, Extends b Object)
=> JavaConverter (a, b) (Tuple2 a b) where
toJava (a, b) = toTuple2 a b
fromJava t = (tup2_1 t, tup2_2 t)

data Tuple3 a b c = Tuple3 (@scala.Tuple3 a b c)
deriving (Class, Show, Eq)

foreign import java unsafe "@new" toTuple3
:: (a <: Object, b <: Object, c <: Object) => a -> b -> c -> Tuple3 a b c

foreign import java unsafe "_1" tup3_1 :: (a <: Object) => Tuple3 a b c -> a

foreign import java unsafe "_2" tup3_2 :: (b <: Object) => Tuple3 a b c -> b

foreign import java unsafe "_3" tup3_3 :: (c <: Object) => Tuple3 a b c -> c

instance (a <: Object, b <: Object, c <: Object)
=> JavaConverter (a, b, c) (Tuple3 a b c) where
toJava (a, b, c) = toTuple3 a b c
fromJava t = (tup3_1 t, tup3_2 t, tup3_3 t)

data Tuple4 a b c d = Tuple4 (@scala.Tuple4 a b c d)
deriving (Class, Show, Eq)

foreign import java unsafe "@new" toTuple4
:: (a <: Object, b <: Object, c <: Object, d <: Object)
=> a -> b -> c -> d -> Tuple4 a b c d

foreign import java unsafe "_1" tup4_1 :: (a <: Object) => Tuple4 a b c d -> a

foreign import java unsafe "_2" tup4_2 :: (b <: Object) => Tuple4 a b c d -> b

foreign import java unsafe "_3" tup4_3 :: (c <: Object) => Tuple4 a b c d -> c

foreign import java unsafe "_4" tup4_4 :: (d <: Object) => Tuple4 a b c d -> d

instance (a <: Object, b <: Object, c <: Object, d <: Object)
=> JavaConverter (a, b, c, d) (Tuple4 a b c d) where
toJava (a, b, c, d) = toTuple4 a b c d
fromJava t = (tup4_1 t, tup4_2 t, tup4_3 t, tup4_4 t)

data Tuple5 a b c d e = Tuple5 (@scala.Tuple5 a b c d e)
deriving (Class, Show, Eq)

foreign import java unsafe "@new" toTuple5
:: (a <: Object, b <: Object, c <: Object, d <: Object, e <: Object)
=> a -> b -> c -> d -> e -> Tuple5 a b c d e

foreign import java unsafe "_1" tup5_1 :: (a <: Object) => Tuple5 a b c d e -> a

foreign import java unsafe "_2" tup5_2 :: (b <: Object) => Tuple5 a b c d e -> b

foreign import java unsafe "_3" tup5_3 :: (c <: Object) => Tuple5 a b c d e -> c

foreign import java unsafe "_4" tup5_4 :: (d <: Object) => Tuple5 a b c d e -> d

foreign import java unsafe "_5" tup5_5 :: (e <: Object) => Tuple5 a b c d e -> e

instance (a <: Object, b <: Object, c <: Object, d <: Object, e <: Object)
=> JavaConverter (a, b, c, d, e) (Tuple5 a b c d e) where
toJava (a, b, c, d, e) = toTuple5 a b c d e
fromJava t = (tup5_1 t, tup5_2 t, tup5_3 t, tup5_4 t, tup5_5 t)

0 comments on commit 09edff1

Please sign in to comment.